void CMFCApplication2Dlg: : OnBnClickedButton1 ()
{
The UpdateData (TRUE);
Cstrings a;
Cstrings strURL, strPostData;
StrURL=_T (" http://w.eydata.net/9edd026122718f37 ");
StrPostData=https://bbs.csdn.net/topics/L "SingleCode=M2AB78665961AA730C0A533B254DD0D2 & amp; Ver=1.0.0 & amp; Mac=";//this is SingleCode card, I'm 100% sure is right, but the returned - 401 is card error
Cstrings STR (_T (" "));
CString& StrHTML=STR;
If (PostDataBase (strURL, strPostData strHTML))
{
A=strHTML;
}
The else {
A +="error";
}
MessageBox (a);
}
BOOL CMFCApplication2Dlg: : PostDataBase (cstrings strURL, cstrings strPostData, CString& StrHTML)
{
Try
{
BOOL bRet.
Cstrings strServer strObject, strHeader strRet;
Unsigned short nPort.
DWORD dwServiceType.
if (! AfxParseURL (strURL, dwServiceType strServer strObject, nPort))
Return FALSE;
CInternetSession sess.//create a session
CHttpFile * pFile;
//////////////////////////////////////////////
CHttpConnection * pServer=sess. GetHttpConnection (strServer, nPort);
If (pServer==NULL)
Return FALSE;
PFile=pServer - & gt; OpenRequest (CHttpConnection: : HTTP_VERB_POST strObject, NULL, 1, NULL, NULL, INTERNET_FLAG_EXISTING_CONNECT);
If (pFile==NULL)
Return FALSE;
PFile - & gt; AddRequestHeaders (_T (" content-type: application/x - WWW - form - urlencoded "));
PFile - & gt; AddRequestHeaders (_T (" Accept: */* "));
PFile - & gt; The SendRequest (NULL, 0, (the LPTSTR) (LPCTSTR) strPostData, strPostData. GetLength ());
Cstrings strSentence;
DWORD dwStatus;
DWORD dwBuffLen=sizeof (dwStatus);
BOOL bSuccess=pFile - & gt; QueryInfo (
HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
& DwStatus, & amp; DwBuffLen);
If (bSuccess & amp; & DwStatus & gt;=200 & amp; & DwStatus<300)
{
Char buffer [1024 * 56];
Memset (buffer, 0, 1024 * 56);
Int nReadCount=0;
While ((nReadCount=pFile - & gt; Read (buffer, 1024 * 56)) & gt; 0)
{
StrHTML +=buffer;
Memset (buffer, 0, 1024 * 56);
}
BRet=TRUE;
}
The else
{
BRet=FALSE;
}
////////////////////////////////////////
PFile - & gt; Close();
Sess. Close ();
Return bRet.
}
The catch (... )
{
Int nCode=GetLastError ();
Return FALSE;
}
}
CodePudding user response:
Fyi:void HexDump) (char * buf, int len, int addr) {
Int I, j, k;
Char binstr [80].
For (I=0; iIf (0==16) (I %) {
Sprintf (binstr, "% x - 08", I + addr);
Sprintf (binstr, "% s % 02 x", binstr, buf (unsigned char) [I]);
} else if (15==16) (I %) {
Sprintf (binstr, "% s % 02 x", binstr, buf (unsigned char) [I]);
Sprintf (binstr, "% s", binstr);
For (j=I - 15; j<=I; J++) {
Sprintf (binstr, "% s % c," binstr, ('! '}
Printf (" % s \ n ", binstr);
} else {
Sprintf (binstr, "% s % 02 x", binstr, buf (unsigned char) [I]);
}
}
If (0! 16)=(I %) {
16 k=16 - (I %);
For (j=0; jSprintf (binstr, "% s", binstr);
}
Sprintf (binstr, "% s", binstr);
K=16 - k;
For (j=I - k; jSprintf (binstr, "% s % c," binstr, ('! '}
Printf (" % s \ n ", binstr);
}
}
CodePudding user response: