Home > Software engineering >  Use MFC HttpSendRequest or openurl cannot obtain baidu or qq website content
Use MFC HttpSendRequest or openurl cannot obtain baidu or qq website content

Time:10-06

Don't know where is the problem, the small website access only available, but want to baidu, qq these website, is to return to 200 but no data content, I am a unicode encoding, below is the code, ask god help me, urgent!
 
Cstrings ChuomaoDlg: : httpGetRequest (cstrings url)
{
CInternetSession m_InetSession;
Cstrings strHtml;
BOOL b=InternetSetOption (m_InetSession INTERNET_OPTION_RESET_URLCACHE_SESSION, NULL, 0);
Try {
CHttpFile * pFile=(CHttpFile *) m_InetSession OpenURL (url);
If (pFile!=NULL)
{
DWORD statusCode;
PFile - & gt; QueryInfoStatusCode (statusCode);
If (statusCode==HTTP_STATUS_OK)
{
MessageBox (_T (" ok "));
TCHAR buf [1024]={0};
Char TMP [2048]={0};
While (pFile - & gt; ReadString (buf, 1024))
{
For (int I=0, j=0; i{
TMP [j]=LOBYTE (buf [I]);//low byte of word
TMP [j + 1)=HIBYTE (buf [I]);//word high byte
}
Cstrings ss (TMP);
StrHtml +=ss;
}
}
}
M_InetSession. Close ();
PFile - & gt; Close ();
The delete pFile;
}
The catch (CInternetException * e) {
TCHAR info [1024]={0};
E - & gt; GetErrorMessage (info, 1024);
}
The catch (CMemoryException * e)
{
TCHAR info [1024]={0};
E - & gt; GetErrorMessage (info, 1024);
}
The catch (CFileException * e)
{
TCHAR info [1024]={0};
E - & gt; GetErrorMessage (info, 1024);
}
The catch (CException * e)
{
TCHAR info [1024]={0};
E - & gt; GetErrorMessage (info, 1024);
}
Return strHtml;
}

CodePudding user response:

Baidu and qq is HTTPS

CodePudding user response:

http://blog.csdn.net/daiyutage/article/details/9567779 MFC parse web pages source code

CodePudding user response:

Note that this is not the code of the problem, is to obtain the value is empty, I open their own projects in the public server no problem, but open the baidu, qq this would be a gain value is empty, but the connection is successful, is the first set the header was they thought is to block the machine?

CodePudding user response:

reference liuyao6298 reply: 3/f
note that this is not the code, is to obtain the value is empty, I open their own projects in the public server no problem, but open the baidu, qq this would be a gain value is empty, but the connection is successful, is the header head set by their thought is to block the machine?

Should be to identify the request is not legitimate, so there is no return content,
You can compare your header information to the browser's header
  • Related