CHttpFile::SendRequest problem
-
Hi I'm trying to submit a web form with method=POST parameter. However, when I run the following code, I'm getting an error saying: "The URL is invalid"
CString strHeaders =_T("Content-Type: application/x-www-form-urlencoded");
CString strFormData = _T("query=murod&a=14");
CInternetSession* pSes=new CInternetSession();
CHttpConnection* pConnection =
pSes->GetHttpConnection(_T("http://www.wutever.com/"));
CHttpFile* pFile =
pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,
_T("/news/"));
BOOL result = pFile->SendRequest(strHeaders,
(LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());What I'm doing wrong?
-
Hi I'm trying to submit a web form with method=POST parameter. However, when I run the following code, I'm getting an error saying: "The URL is invalid"
CString strHeaders =_T("Content-Type: application/x-www-form-urlencoded");
CString strFormData = _T("query=murod&a=14");
CInternetSession* pSes=new CInternetSession();
CHttpConnection* pConnection =
pSes->GetHttpConnection(_T("http://www.wutever.com/"));
CHttpFile* pFile =
pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,
_T("/news/"));
BOOL result = pFile->SendRequest(strHeaders,
(LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());What I'm doing wrong?
LOL I found my mistake :laugh:
CHttpConnection* pConnection =
pSes->GetHttpConnection(_T("http://www.wutever.com/"));Looks like I should not include "http://" in the url. Now another problem: I'm able to send the request, but how do I get the response? The response will be a web page source? After sending the request I wrote the content of the pFile(CHttpFile class) to a file and based on that file I'm guessing either I didn't send the request, or either I didn't get the response. What should I do to get the response?
-
LOL I found my mistake :laugh:
CHttpConnection* pConnection =
pSes->GetHttpConnection(_T("http://www.wutever.com/"));Looks like I should not include "http://" in the url. Now another problem: I'm able to send the request, but how do I get the response? The response will be a web page source? After sending the request I wrote the content of the pFile(CHttpFile class) to a file and based on that file I'm guessing either I didn't send the request, or either I didn't get the response. What should I do to get the response?
after calling, CHttpFile::SendRequest u should call CHttpFile::QueryInfoStatusCode u will get status code...Http Error Codes... if status code is 200, then u can download the response using CHttpFile::Read. response may contain Html content or File Content if u have called to pdf,doc etc. Regards, Swapnil
-
after calling, CHttpFile::SendRequest u should call CHttpFile::QueryInfoStatusCode u will get status code...Http Error Codes... if status code is 200, then u can download the response using CHttpFile::Read. response may contain Html content or File Content if u have called to pdf,doc etc. Regards, Swapnil