5

here is my code:

using HttpClient client = new HttpClient();

try
{
    HttpResponseMessage response = await client.GetAsync("http://131.189.89.86:11920/SetupWizard.aspx/yNMgLvRtUj");
}
catch (HttpRequestException e)
{
    Console.WriteLine($"Request error: {e.Message}");
}

and it gives me this error: System.Net.Http.HttpRequestException: 'Received an invalid status line: 'HTTP/2 200 '.'

I also tried to downgrade Http Version like this:

var request = new HttpRequestMessage(HttpMethod.Get, "http://131.189.89.86:11920/SetupWizard.aspx/yNMgLvRtUj")
{
    Version = new Version(1, 1)
};
HttpResponseMessage response = await client.SendAsync(request);

but no success.

here is a TCP hack which works even server is broken:

    var host = "131.189.89.86";
    var port = 11920;

    using var client = new TcpClient();
    await client.ConnectAsync(host, port);

    using var stream = client.GetStream();

    // Manually craft an HTTP/1.0 style request
    var request = "GET /SetupWizard.aspx/yNMgLvRtUj HTTP/1.0\r\nHost: 131.189.89.86\r\nConnection: close\r\n\r\n";
    byte[] requestBytes = Encoding.ASCII.GetBytes(request);
    await stream.WriteAsync(requestBytes, 0, requestBytes.Length);

    byte[] buffer = new byte[8192];
    int bytesRead;
    var response = new StringBuilder();

    do
    {
        bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length);
        response.Append(Encoding.ASCII.GetString(buffer, 0, bytesRead));
    } while (bytesRead > 0);

    Console.WriteLine("---- RAW SERVER RESPONSE ----");
    Console.WriteLine(response.ToString());

but how to do it via httpclient? any hack or trick?

14
  • 1
    See stackoverflow.com/questions/77149228/… - problem with server? Commented Apr 28 at 8:13
  • 1
    I'm certain the server is the issue. http.app gives following error: "Expected dot: b'HTTP/2 200 ' ^" Postman gives similar Commented Apr 28 at 10:52
  • 1
    Server is at fault here. Commented Apr 28 at 17:43
  • 2
    @InsideMan maybe the problem is from server, but there's no but or maybe, and this isn't a small error. WebForms never supported HTTP/2 and you can't just hack support by changing the response payload . HTTPS is a defacto requirement - all major browsers require at least TLS v1.2 AND the ALPN extension. And no, we can't open that URL. HTTP/2 is enabled by default in ASP.NET Core applications, even Minimal APIs. Use ASP.NET Core if you really want to use HTTP/2 Commented Apr 30 at 8:22
  • 2
    As for others will skip such small errors are you sure, and what "small error" would that be? There are 2 errors in that status line. Using the wrong protocol is a critical error. Ignoring an invalid reason phrase is indeed a small error but so rare that the HttpClient team gave it a very low priority. cURL dumps the raw response, it doesn't try to parse it, and as the cURL docs say HTTP/2 won't be used with http:// URLs unless you use curl --http2 http://example.com/ Commented Apr 30 at 9:08

0

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.