#include <string>
#include <iostream>
#include <windows.h>
#include <winhttp.h>
#pragma comment(lib,"winhttp.lib")
#pragma comment(lib,"user32.lib")
void main()
{
DWORD dwSize = 0;
DWORD dwOut = 0;
LPVOID lpOutBuffer = NULL;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;
BOOL bResults = FALSE;
hSession=WinHttpOpen(L"User Agent",WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,WINHTTP_NO_PROXY_NAME,WINHTTP_NO_PROXY_BYPASS,0);
if(hSession)
{
hConnect=WinHttpConnect(hSession,L"www.sqtxj.com",10087,0);
}
if(hConnect)
{
hRequest=WinHttpOpenRequest(hConnect, L"GET",L"/webservice/GetLastGpsData?VehicleNo=WENYX001",L"HTTP/1.1", WINHTTP_NO_REFERER,WINHTTP_DEFAULT_ACCEPT_TYPES,0);
}
if(hRequest)
{
bResults=WinHttpSendRequest(hRequest,WINHTTP_NO_ADDITIONAL_HEADERS, 0,WINHTTP_NO_REQUEST_DATA, 0, 0, 0 );
}
if(bResults)
{
bResults=WinHttpReceiveResponse(hRequest,NULL);
}
if(bResults)
{
// bResults=WinHttpQueryHeaders(hRequest,WINHTTP_QUERY_RAW_HEADERS_CRLF, WINHTTP_HEADER_NAME_BY_INDEX,NULL,&dwSize,WINHTTP_NO_HEADER_INDEX);
// if( GetLastError( ) == ERROR_INSUFFICIENT_BUFFER)
// {
// lpOutBuffer = new WCHAR[dwSize/sizeof(WCHAR)];
//
// bResults = WinHttpQueryHeaders(hRequest,WINHTTP_QUERY_RAW_HEADERS_CRLF,WINHTTP_HEADER_NAME_BY_INDEX, lpOutBuffer, &dwSize,WINHTTP_NO_HEADER_INDEX);
// }
lpOutBuffer = new WCHAR[200];
memset(lpOutBuffer, 0, 200);
bResults = WinHttpReadData(hRequest, lpOutBuffer, 200, &dwOut);
}
if(bResults)
{
printf("Rev: %s\n",lpOutBuffer);
}
delete [] lpOutBuffer;
if (hRequest) WinHttpCloseHandle(hRequest);
if (hConnect) WinHttpCloseHandle(hConnect);
if (hSession) WinHttpCloseHandle(hSession);
system("pause");
}