hsession=::InternetOpen("IE",INTERNET_OPEN_TYPE_DIRECT,NULL,INTERNET_INVALID_PORT_NUMBER,0);
if(hsession==NULL)
{
return FALSE;
}
// 连接到http://www.baidu.com/
hconnect=::InternetConnect(hsession,"www.baidu.com",INTERNET_INVALID_PORT_NUMBER,"","",INTERNET_SERVICE_HTTP,0,0);
if(hconnect==NULL)
{
return FALSE;
}
//hhttpfile=::HttpOpenRequest(hconnect,"GET","/MSDN/MSDNINFO/",HTTP_VERSION,NULL,0,INTERNET_FLAG_FROM_CACHE,0);
hhttpfile=::HttpOpenRequest(hconnect,"GET","HTTP/1.1",HTTP_VERSION,NULL,0,INTERNET_FLAG_FROM_CACHE,0);
if(hhttpfile==NULL)
{
return FALSE;
} BOOL bsendRequest=::HttpSendRequest(hhttpfile,NULL,0,NULL,0);
if(bsendRequest==TRUE)
{
MessageBox("ok-4");//???
}

解决方案 »

  1.   

    HttpSendRequest function
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa384247(v=vs.85).aspx
    Return value
    Returns TRUE if successful, or FALSE otherwise. To get extended error information, call GetLastError.WinINet Constants
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa385448(v=vs.85).aspx
    Error Messages 错误标识说明(GetLastError)
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa385465(v=vs.85).aspx
    HTTP Status Codes HTTP状态码
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa384325(v=vs.85).aspx
      

  2.   

    没有用!我把HttpOpenRequest中的参数改了就好了,不过我收到时显示出错的网页!!
      

  3.   

    hhttpfile=::HttpOpenRequest(hconnect,"GET","HTTP/1.1",HTTP_VERSION,NULL,0,INTERNET_FLAG_KEEP_CONNECTION,0);
    这样请求有问题?请具体帮我指出一下,谢谢
      

  4.   

    HINTERNET hOpen = InternetOpen( m_AgentName.c_str(),INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); HINTERNET hConnect = InternetConnect(hOpen, m_Host.c_str(), 80, _T(""), _T(""), INTERNET_SERVICE_HTTP, NULL, NULL); HINTERNET hRequest = HttpOpenRequest(hConnect, m_Method.c_str(), m_Url.c_str(), HTTP_VERSION, m_Refer.c_str(), NULL ,INTERNET_FLAG_DONT_CACHE, NULL); const char *pLoginBody = pBody.c_str();
    int m_BodyLen = static_cast <DWORD> (strlen(pLoginBody));BOOL hSendRequest = HttpSendRequest(hRequest, m_Header.c_str(),m_Header.length(), (LPVOID)(pLoginBody), m_BodyLen );if(!hSendRequest) 
    return false;InternetCloseHandle(hRequest); 
    InternetCloseHandle(hConnect); 
    InternetCloseHandle(hOpen);