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 ?

Gordon
  • 73
  • 7
  • 2
    in Postman you use https in your c# code just http. – Ralf Nov 05 '22 at 12:40
  • I have tried both – Gordon Nov 05 '22 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");` – Ralf Nov 05 '22 at 13:15

1 Answers1

1

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#

Joe_DM
  • 985
  • 1
  • 5
  • 12