在Win7 32位系統的客戶電腦上運行到發送Http請求的時候出錯
bRet = HttpSendRequest(m_hRequest, strHeader.c_str(), dwHeaderSize, (LPVOID)strPostData.c_str(), dwSize);
if (!bRet)
{
CString strT;
strT.Format("資料發送失敗,錯誤代碼:%d", GetLastError());
MessageBox(strT);
return;
}
有些客戶電腦(如xp)可以運行,但是個別幾個客戶電腦運行失敗,錯誤代碼為2,找不到檔案!
求大神,指點,是系統哪里少庫還是網路設定相關問題!
uj5u.com熱心網友回復:
參考MSDN的例子
// Open Internet session.
HINTERNET hSession = ::InternetOpen("MSDN SurfBear",
PRE_CONFIG_INTERNET_ACCESS,
NULL,
INTERNET_INVALID_PORT_NUMBER,
0) ;
// Connect to www.microsoft.com.
HINTERNET hConnect = ::InternetConnect(hSession,
"www.microsoft.com",
INTERNET_INVALID_PORT_NUMBER,
"",
"",
INTERNET_SERVICE_HTTP,
0,
0) ;
// Request the file /MSDN/MSDNINFO/ from the server.
HINTERNET hHttpFile = ::HttpOpenRequest(hConnect,
"GET",
"/MSDN/MSDNINFO/",
HTTP_VERSION,
NULL,
0,
INTERNET_FLAG_DONT_CACHE,
0) ;
// Send the request.
BOOL bSendRequest = ::HttpSendRequest(hHttpFile, NULL, 0, 0, 0);
// Get the length of the file.
char bufQuery[32] ;
DWORD dwLengthBufQuery = sizeof(bufQuery);
BOOL bQuery = ::HttpQueryInfo(hHttpFile,
HTTP_QUERY_CONTENT_LENGTH,
bufQuery,
&dwLengthBufQuery) ;
// Convert length from ASCII string to a DWORD.
DWORD dwFileSize = (DWORD)atol(bufQuery) ;
// Allocate a buffer for the file.
char* buffer = new char[dwFileSize+1] ;
// Read the file into the buffer.
DWORD dwBytesRead ;
BOOL bRead = ::InternetReadFile(hHttpFile,
buffer,
dwFileSize+1,
&dwBytesRead);
// Put a zero on the end of the buffer.
buffer[dwBytesRead] = 0 ;
// Close all of the Internet handles.
::InternetCloseHandle(hHttpFile);
::InternetCloseHandle(hConnect) ;
::InternetCloseHandle(hSession) ;
// Display the file in an edit control.
pEditCtrl->SetWindowText(buffer) ;
uj5u.com熱心網友回復:
回復樓上,@zgl7903按照你MSDN的例子,在客戶電腦也是運行到HttpSendRequest 就失敗,GetLastError錯誤代碼是2
uj5u.com熱心網友回復:
運行命令列 重置下 winsock 試試看netsh winsock reset
uj5u.com熱心網友回復:
@zgl7903netsh winsock reset 這個方式不行的!
關鍵客戶電腦上用Delphi程式可以實行Http通訊
uj5u.com熱心網友回復:
是不是VC相關的庫環境等有問題,把你VC的運行時庫也跟你程式一起帶上uj5u.com熱心網友回復:
與環境有關系、xp32位的,win7有64位的庫有做區別嗎,這個有影響嗎uj5u.com熱心網友回復:
用抓包工具分別抓個包比對一下看看有什么不同?轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/73848.html
標籤:網絡編程
上一篇:請問哪個是對話框顯示完成的訊息?
