0

When I attempt an webrequest using c# I get error 404, the same request works in both python and Post man. Here is my c# code:

public void GetTorrentsTest3()
{
    var url = "http://oneom.is/ep";
    var request = WebRequest.Create(url);
    request.Method = "GET";

    using var webResponse = request.GetResponse();
    using var webStream = webResponse.GetResponseStream();

    using var reader = new StreamReader(webStream);
    var data = reader.ReadToEnd();

    Console.WriteLine(data);
}

Here the same request in PostMan:

enter image description here

Any ideas ?

3
  • 2
    in Postman you use https in your c# code just http. Commented Nov 5, 2022 at 12:40
  • I have tried both Commented Nov 5, 2022 at 13:01
  • 1
    The site seems to check the UserAgent header and the WebRequest class does not send one of its own. Add such a header yourself like request.Headers.Add(HttpRequestHeader.UserAgent, "myLovelyUserAgent"); Commented Nov 5, 2022 at 13:15

1 Answer 1

2

It's not anything to do with your code. That specific URL seem to be upset that you are not providing a User Agent header.

I'd suggest that all you need do is set your user agent, for which I refer you to How to set User Agent with System.Net.WebRequest in c#

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.