3,055
社区成员
发帖
与我相关
我的任务
分享
HINTERNET hInternet = ::InternetOpen(_T("SPRReader"),
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,
NULL,
0) ;
if (hInternet==NULL)
{
return FALSE;
}
DWORD header = 0 ;
CString strServer = "www.xxxxxxx.com";
HINTERNET hHttp = ::InternetConnect(hInternet,
strServer,
INTERNET_DEFAULT_HTTP_PORT,
NULL,
NULL,
INTERNET_SERVICE_HTTP,
0,
1) ;
if (hHttp==NULL)
{
return FALSE;
}
// send data to server
CString strData="DATA";
CString strPath="/111/aaa.jsp";
LPCTSTR AcceptTypes[2] = {_T("*/*"), NULL};
HINTERNET hReq = ::HttpOpenRequest(hHttp,
_T("POST"),
strPath,
HTTP_VERSION,
NULL,
AcceptTypes,
INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE,
0) ;
if (hReq==NULL)
{
return FALSE;
}
LPTSTR hdrs = {_T("Content-Type: application/x-www-form-urlencoded;charset=GB2312")};
// Send the request.
if (HttpSendRequest(hReq,
hdrs,
strlen(hdrs),
(LPVOID)(LPCSTR)strData,
strData.GetLength()))
{
DWORD dwLengthBufQuery = 32; //sizeof(bufQuery);
TCHAR szStatusCode[32];
DWORD dwInfoSize = sizeof(szStatusCode);
if (HttpQueryInfo (hReq,
HTTP_QUERY_STATUS_CODE,
szStatusCode,
&dwInfoSize,
NULL))
{
szStatusCode[dwInfoSize]=0;
long nStatusCode = _ttol(szStatusCode);
if (nStatusCode == HTTP_STATUS_OK)
{
//record and write back to register
}
}
}
InternetCloseHandle(hReq);
InternetCloseHandle(hHttp);
InternetCloseHandle(hInternet);
hReq = NULL;
hHttp = NULL;
hInternet = NULL;