Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get HTTP status code from WinHttp request?

Tags:

winhttp

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?

like image 471
ghord Avatar asked May 28 '14 08:05

ghord


People also ask

How can I get HTTP status code?

Just use Chrome browser. Hit F12 to get developer tools and look at the network tab. Shows you all status codes, whether page was from cache etc.

What is a HTTP response 443?

TCP port 443 is the default port used by HTTPS. If this port is blocked on any server or device from your computer to a given destination, such as www.Microsoft.com, your connection to any https site will fail and your browser will return an error message like "Secure Connection Failed" or "Page Cannot be Displayed" .

What is request status code?

An HTTP status code is a server response to a browser's request. When you visit a website, your browser sends a request to the site's server, and the server then responds to the browser's request with a three-digit code: the HTTP status code.


1 Answers

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);
like image 140
asfdfdfd Avatar answered Sep 16 '22 18:09

asfdfdfd