Home > Mobile >  Http request works from Postman, Python but not from C# error 404
Http request works from Postman, Python but not from C# error 404

Time:11-05

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 ?

CodePudding user response:

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#

  • Related