Home > Software engineering >  MFC POST Web server why I filled in card server cue CARDS guhya error, is coding issues?
MFC POST Web server why I filled in card server cue CARDS guhya error, is coding issues?

Time:10-11

 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:

reference 1st floor zhao4zhong1 response:
are for reference only:
 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);
}
}

What do you mean turn hexadecimal, small white under the trouble to explain comments

CodePudding user response:

Use Fiddler caught, browser to contrast the POST request and what is the difference between your POST request

CodePudding user response:

Login is easy to swim WEBAPI, who knows what is wrong with MFCpost, how is the post return error

CodePudding user response:

Recommendations have to learn to use the original poster caught software such as wireshark

CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related