Home > Back-end >  The WINHTTP access web problem for help
The WINHTTP access web problem for help

Time:12-21

#include
#include
#include


The main ()
{

DWORD dwSize=0;
DWORD dwDownloaded=0;
LPSTR pszOutBuffer;
BOOL bResults=FALSE;
HINTERNET hSession=NULL,
HConnect=NULL,
HRequest=NULL;

//Use WinHttpOpen to obtain a session handle.
HSession=WinHttpOpen (L "WinHTTP Example/1.0",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, 0);

//Specify an HTTP server.
If (hSession)
HConnect=WinHttpConnect (hSession, L "www.microsoft.com",
INTERNET_DEFAULT_HTTPS_PORT, 0);

//Create an HTTP request handle.
If (hConnect)
HRequest=WinHttpOpenRequest (hConnect, L "GET", NULL,
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
WINHTTP_FLAG_SECURE);

//Send a request.
If (hRequest)
BResults=WinHttpSendRequest (hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS,
WINHTTP_NO_REQUEST_DATA 0, 0,
0, 0);


//the End of the request.
If (bResults)
BResults=WinHttpReceiveResponse (hRequest, NULL);

//Keep checking for data until there is nothing left.
If (bResults)
{
Do
{
//Check for the available data.
DwSize=0;
if (! WinHttpQueryDataAvailable (hRequest, & amp; DwSize))
{
Printf (" Error % u in WinHttpQueryDataAvailable. \ n ",
GetLastError ());
break;
}

//No more available data.
if (! DwSize)
break;

//the Allocate space for the buffer.
PszOutBuffer=new char [dwSize + 1];
if (! PszOutBuffer)
{
Printf (" Out of memory \ n ");
break;
}

//Read the Data.
ZeroMemory (pszOutBuffer dwSize + 1);

if (! PszOutBuffer WinHttpReadData (hRequest, (LPVOID),
DwSize, & amp; DwDownloaded))
{
Printf (" Error % u in WinHttpReadData. \ n ", GetLastError ());
}
The else
{
Printf (" % s ", pszOutBuffer);
}

//Free the memory allocated to the buffer.
The delete [] pszOutBuffer;

//This condition should never be reached since WinHttpQueryDataAvailable
//reported that there are bits to read.
if (! DwDownloaded)
break;

} while (dwSize & gt; 0);
}
The else
{
//Report any errors.
Printf (" Error % d has occurred. \ n ", GetLastError ());
}

//Close any open handles.
If (hRequest) WinHttpCloseHandle (hRequest);
If (hConnect) WinHttpCloseHandle (hConnect);
If (hSession) WinHttpCloseHandle (hSession);
}






After the operation error "lack of type specifier - is assumed to be int, note: c + + does not support default int"

Help bosses
  • Related