求救一个关于windows上c++调用winhttp库中的问题
本人第一次用winhttp实现一个客户端与服务器通信的程序,但是第一次使用winhttp,在网络上搜索到的一些代码调用的时候都不是很理想,在这里求下大神帮帮忙,我是实现一个从cul为http://192.168.1.90:8080/Client/Index?ip=180.168.1.80中获取网页的内容,其中的内容是一串字符串:{"name":"123456789123456789123456789"},调用的代码为:
这段代码中当
LPSTR pszData = "WinHttpWriteData Example";
DWORD dwBytesWritten = 0;
BOOL bResults = FALSE;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;
// Use WinHttpOpen to obtain a session handle.
hSession = WinHttpOpen( L"A WinHTTP Example Program/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"http://192.168.1.90:8080/Client/Index?ip=180.168.1.80",
INTERNET_DEFAULT_HTTP_PORT, 0);
// Create an HTTP Request handle.
if (hConnect)
hRequest = WinHttpOpenRequest( hConnect, L"GET",
L"/writetst.txt",
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
0);
// Send a Request.
if (hRequest)
bResults = WinHttpSendRequest( hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS,
0, WINHTTP_NO_REQUEST_DATA, 0,
(DWORD)strlen(pszData), 0);
// End the request.
if (bResults)
bResults = WinHttpReceiveResponse( hRequest, NULL);
// 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);