Home > Software engineering >  WinHttpSendRequest under Windows 7 return error code 12029.
WinHttpSendRequest under Windows 7 return error code 12029.

Time:09-17

The same code, the same data at the request of WinHttpSendRequest normal interface under win10 and doing the system implementation,
Under Windows 7 execution returns false, getlasterror get 12029.

After open the HTTP debuger caught under the Windows 7 tools, perform normal again,
Open the fiddler caught under Windows 7 tools, implementation returns false, but caught tools did not catch the request data,
Ps: under the win10 system, open the fiddler also can't catch the request data, but the code execution is normal, return true,


Under the guidance of the great god, the strange question, about how to analysis,

CodePudding user response:

12029 ERROR_WINHTTP_CANNOT_CONNECT
Try the MSDN examples of reference
 
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 ());

//the Allocate space for the buffer.
PszOutBuffer=new char [dwSize + 1];
if (! PszOutBuffer)
{
Printf (" Out of memory \ n ");
DwSize=0;
}
The else
{
//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;
}

} while (dwSize> 0);


//Report any errors.
if (! BResults)
Printf (" Error % d has occurred. \ n ", GetLastError ());

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

  • Related