Home > Software engineering >  WinInet ways to Get the Post some website can Get to the source, while others can only Get to the pa
WinInet ways to Get the Post some website can Get to the source, while others can only Get to the pa

Time:10-19

WinInet ways to Get the Post, some websites can Get to the source, while others can only Get to the part, or even return bad request, but I don't know what went wrong, ask the great spirit guide, I am a UNICODE programs, can only take part of the code, InternetReadFile (hHttpRequest pbtBuf, 1024, & amp; NCount); Read only once and the second reading, or the content of the last read pbtBuf, nCount into 0. If I put Buf for large enough memory, you can read all the source code, but read the source code is problematic, and visit some sites will not appear this kind of problem, ask the great spirit guide, please! Upset me two days, also did not find problems,
Out of the question, HttpSendRequest call fails, error code is 12150
 
Char * CWinInetOperate: : WebVisit (cstrings strUrl, cstrings strVisitType, char * pcSubmitData, cstrings strSubmitCookies, cstrings strSubjoinProtocolHeader,
BOOL bNoRedirect, cstrings strProxyAddress)
{
CStringOperate c_StrOperate;
Cstrings strTempUrl=strUrl;
BOOL bHttps=FALSE;
StrTempUrl. MakeLower ();
If (strTempUrl. Left (8)=="https://" L)
BHttps=TRUE;
Cstrings strUserAgent;
If (strSubjoinProtocolHeader. Find (L) "the user-agent:"!=1)
StrUserAgent=c_StrOperate. GetStringMiddle (strSubjoinProtocolHeader, L "the user-agent:" L "\ r \ n");
The else
StrUserAgent=L "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1) ";
HINTERNET HINTERNET;
If (strProxyAddress. IsEmpty ())
HInternet=InternetOpen (strUserAgent INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0).
The else
{
If (bHttps)
HInternet=InternetOpen (strUserAgent INTERNET_OPEN_TYPE_PROXY, strProxyAddress, NULL, 0).
The else
HInternet=InternetOpen (strUserAgent INTERNET_OPEN_TYPE_DIRECT, L "HTTP=" + strProxyAddress, NULL, 0).
}
if (! HInternet)
return NULL;
HINTERNET hInternetConnect;
HInternetConnect=InternetConnect (hInternet, GetDomain (strUrl), GetPort (strUrl), NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0).
if (! HInternetConnect)
{
InternetCloseHandle (hInternetConnect);
InternetCloseHandle (hInternet);
return NULL;
}
Int nRequestSign=INTERNET_FLAG_RELOAD | INTERNET_COOKIE_THIRD_PARTY;
If (strSubmitCookies. IsEmpty ()==FALSE)
NRequestSign |=INTERNET_FLAG_NO_COOKIES;
If (bNoRedirect)
NRequestSign |=INTERNET_FLAG_NO_AUTO_REDIRECT;
If (bHttps)
NRequestSign |=INTERNET_FLAG_SECURE;
The else
NRequestSign |=INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS;
PCTSTR rgpszAcceptTypes []={L "text/*", NULL};
HINTERNET hHttpRequest=HttpOpenRequest (hInternetConnect strVisitType, GetPageAddress (strUrl), L "HTTP/1.1", NULL, NULL, nRequestSign, 0).
if (! HHttpRequest)
{
InternetCloseHandle (hInternet);
InternetCloseHandle (hInternetConnect);
InternetCloseHandle (hHttpRequest);
return NULL;
}

If (strSubjoinProtocolHeader. IsEmpty ())
StrSubjoinProtocolHeader=L "Accept: */*";
The else
{
If (strSubjoinProtocolHeader. Find (L "Accept")==1)
StrSubjoinProtocolHeader=strSubjoinProtocolHeader + L "\ r \ n" + L "Accept: */*";
}
If (strSubjoinProtocolHeader. Find the "Referer:" (L)==1)
StrSubjoinProtocolHeader=strSubjoinProtocolHeader + L "\ r \ n" + L "Referer:" + strUrl;
If (strSubjoinProtocolHeader. Find "Accept - Language:" (L)==1)
StrSubjoinProtocolHeader=strSubjoinProtocolHeader + L "\ r \ n" + L "Accept - Language: useful - cn";
If (strSubjoinProtocolHeader. Find "content-type:" (L)==1)
StrSubjoinProtocolHeader=strSubjoinProtocolHeader + L "\ r \ n" + L "content-type: application/x - WWW - form - urlencoded";
If (strSubmitCookies. IsEmpty ()==FALSE)
StrSubjoinProtocolHeader=strSubjoinProtocolHeader + L "\ r \ n" + L "Cookie:" + strSubmitCookies;
Cstrings strTempVisitType=strVisitType;
StrTempVisitType. MakeLower ();
If (strTempVisitType==L "get")
HttpSendRequest (hHttpRequest, strSubjoinProtocolHeader, strSubjoinProtocolHeader GetLength (), NULL, 0).
The else
{
DWORD dwLength;
If (pcSubmitData=NULL https://bbs.csdn.net/topics/=
DwLength=0;
The else
DwLength=strlen (pcSubmitData) + 1;
HttpSendRequest (hHttpRequest, strSubjoinProtocolHeader, strSubjoinProtocolHeader GetLength (), pcSubmitData, dwLength);
}

DWORD nCount;
Byte * pbtBuf=new byte [1024];
CByteArray btaryWebCode;
Memset (pbtBuf, 0, 1024);
BOOL bFlag;
Do
{
BFlag=InternetReadFile (hHttpRequest pbtBuf, 1024, & amp; NCount);
For (DWORD I=0; I & lt; NCount; I++)
BtaryWebCode. Add (pbtBuf [I]);
} while (nCount);
NCount=btaryWebCode. GetCount ();
Char * pcWebCode=new char [nCount + 1];
Memset (pcWebCode, 0, nCount + 1);
For (DWORD I=0; I & lt; NCount; I++)
PcWebCode [I]=btaryWebCode. GetAt (I);
/* CFile file;
File. The Open (L "C: \ \ Users \ \ Administrator USER - 20150718 lb \ \ Desktop \ \ 1. TXT", CFile: : modeReadWrite);
File. The Write (pcWebCode, nCount);
File. The Close (); */

InternetCloseHandle (hInternet);
InternetCloseHandle (hInternetConnect);
InternetCloseHandle (hHttpRequest);
Return pcWebCode;
}



CodePudding user response:

Is the URL Encode the problem? What do you want to take a look at the website of the encoding format, different site coding format is not the same ~

CodePudding user response:

nullnullnullnullnullnull
  • Related