Project now need to upload files over HTTP, written in c + +, using the CHttpFile class, download: no problem, but upload don't know how to write, specific requirements are as follows the
CodePudding user response:
Bumps on your own, online, etc., more worry, thank you god
CodePudding user response:
Refer to
cstrings strHttpName="http://localhost/TestReg/RegForm.aspx";//need to submit the data page
Cstrings strFormData="https://bbs.csdn.net/topics/username=abc&password=123";//need to submit the data
CInternetSession sess.
CHttpFile * fileGet;
Cstrings strHeaders=_T (" content-type: application/x - WWW - form - urlencoded ");//request header
Try
{
FileGet=(CHttpFile *) sess. OpenURL (strHttpName);//open the file
}
The catch (CException * e)
{
FileGet=0;
Throw;
}
Cstrings strSentence strGetSentence="";
If (fileGet)
{
DWORD dwStatus;
DWORD dwBuffLen=sizeof (dwStatus);
BOOL bSuccess=fileGet - & gt; QueryInfo (HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, & amp; DwStatus, & amp; DwBuffLen);
If (bSuccess & amp; & DwStatus>=200 & amp; & DwStatus<300)
{
BOOL result=fileGet - & gt; The SendRequest (strHeaders, (LPVOID) (LPCTSTR) strFormData, strFormData. GetLength ());
While (fileGet - & gt; ReadString (strSentence))//read committed data results returned after
{
StrGetSentence=strGetSentence + strSentence + char (13) + char (10);
}
AfxMessageBox (strGetSentence);//show return web content
}
The else
{
StrSentence. The Format (" POST error, error code: % d ", dwStatus);
AfxMessageBox (strSentence);
}
FileGet - & gt; Close ();
The delete fileGet;
}
The else
AfxMessageBox (" cannot find a web page file!" );
Sess. Close ();
CodePudding user response:
http://blog.csdn.net/love3s/article/details/7936315 CodePudding user response:
refer to the second floor smwhotjay response: Refer to cstrings strHttpName="http://localhost/TestReg/RegForm.aspx";//need to submit the data page Cstrings strFormData="https://bbs.csdn.net/topics/username=abc&password=123";//need to submit the data CInternetSession sess. CHttpFile * fileGet; Cstrings strHeaders=_T (" content-type: application/x - WWW - form - urlencoded ");//request header Try { FileGet=(CHttpFile *) sess. OpenURL (strHttpName);//open the file } The catch (CException * e) { FileGet=0; Throw; } Cstrings strSentence strGetSentence=""; If (fileGet) { DWORD dwStatus; DWORD dwBuffLen=sizeof (dwStatus); BOOL bSuccess=fileGet - & gt; QueryInfo (HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, & amp; DwStatus, & amp; DwBuffLen); If (bSuccess & amp; & DwStatus>=200 & amp; & DwStatus<300) { BOOL result=fileGet - & gt; The SendRequest (strHeaders, (LPVOID) (LPCTSTR) strFormData, strFormData. GetLength ()); While (fileGet - & gt; ReadString (strSentence))//read committed data results returned after { StrGetSentence=strGetSentence + strSentence + char (13) + char (10); } AfxMessageBox (strGetSentence);//show return web content } The else { StrSentence. The Format (" POST error, error code: % d ", dwStatus); AfxMessageBox (strSentence); } FileGet - & gt; Close (); The delete fileGet; } The else AfxMessageBox (" cannot find a web page file!" ); Sess. Close (); Thank you, I'll try, if successful, thank you very much CodePudding user response:
Quote: refer to the second floor smwhotjay response: Refer to cstrings strHttpName="http://localhost/TestReg/RegForm.aspx";//need to submit the data page Cstrings strFormData="https://bbs.csdn.net/topics/username=abc&password=123";//need to submit the data CInternetSession sess. CHttpFile * fileGet; Cstrings strHeaders=_T (" content-type: application/x - WWW - form - urlencoded ");//request header Try { FileGet=(CHttpFile *) sess. OpenURL (strHttpName);//open the file } The catch (CException * e) { FileGet=0; Throw; } Cstrings strSentence strGetSentence=""; If (fileGet) { DWORD dwStatus; DWORD dwBuffLen=sizeof (dwStatus); BOOL bSuccess=fileGet - & gt; QueryInfo (HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, & amp; DwStatus, & amp; DwBuffLen); If (bSuccess & amp; & DwStatus>=200 & amp; & DwStatus<300) { BOOL result=fileGet - & gt; The SendRequest (strHeaders, (LPVOID) (LPCTSTR) strFormData, strFormData. GetLength ()); While (fileGet - & gt; ReadString (strSentence))//read committed data results returned after { StrGetSentence=strGetSentence + strSentence + char (13) + char (10); } AfxMessageBox (strGetSentence);//show return web content } The else { StrSentence. The Format (" POST error, error code: % d ", dwStatus); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull