3

With WinHTTP, WinHttpReceiveResponse will return ERROR_WINHTTP_INVALID_SERVER_RESPONSE if there is something wrong with an HTTP header for example.

Is there anyway to get to the data that was returned, despite the fact that it was malformed?

DougN
  • 4,407
  • 11
  • 56
  • 81
  • There are a lot of ways in different languages. Which programming language do you prefer?? – Searush Oct 26 '12 at 19:12
  • For example, I can tell you a way with ASP.NET/VB (without iframes) – Searush Oct 26 '12 at 19:20
  • WinHTTP is an API. So any language will do, but I don't need example code, just an explanation how to get the data from WinHTTP after a bad response is returned. But it has to use WinHTTP – DougN Oct 26 '12 at 19:38
  • Maybe you try "MSXML2.ServerXMLHTTP" ? It's easier,and needs 5 lines of code to get HTTP response. – Searush Oct 26 '12 at 20:19
  • This is in a Windows service. WinHTTP is requirement for the project and the question. – DougN Oct 27 '12 at 01:55

1 Answers1

2

The direct approach would be to bypass the WinHTTP API in this case and do a "raw" read using a socket and do your best to try to interpret the response header.

If it's possible to find a line matching content-length, you might, at least, be able to get all the data even though the header is invalid. To try this approach, either run your code in a debugger and look at what is actually sent by the web server or try to capture the packet stream and look inside the first packet to find the raw bytes.

You result will, obviously, depend on the actual problem with the response.

HonkyTonk
  • 1,961
  • 11
  • 11
  • 1
    I can't get away from the WinHTTP API very easily -- it handles SSL, authentication, proxies, etc for me and I don't relish having to re-write all of that. In my case, this will be production code that, when it hits an error, would dump the raw code to a log so we could figure out why it wouldn't load. – DougN Oct 25 '12 at 22:02