11

This page on msdn contains definitions of HTTP status codes presumably used in WinHTTP. Is there a way to retrieve HTTP status code from request made in WinHttp?

The only way I've found to get to response text, is to call WinHttpQueryHeaders, which returns HTTP response like this:

HTTP/1.1 404 Not Found
Date: Wed, 28 May 2014 08:20:29 GMT
Content-Length: 0
Server: Microsoft-HTTPAPI/2.0

Do I have to parse this string by myself to get status code, or is there some way already provided by WinHttp to do this?

Dmytro Plekhotkin
  • 1,965
  • 2
  • 23
  • 47
ghord
  • 13,260
  • 6
  • 44
  • 69

1 Answers1

17

Use this to read http status code (hRequest - handle of the request).

DWORD dwStatusCode = 0;
DWORD dwSize = sizeof(dwStatusCode);

WinHttpQueryHeaders(hRequest, 
    WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, 
    WINHTTP_HEADER_NAME_BY_INDEX, 
    &dwStatusCode, &dwSize, WINHTTP_NO_HEADER_INDEX);
Roman R.
  • 68,205
  • 6
  • 94
  • 158
asfdfdfd
  • 354
  • 4
  • 9