Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CHttpFile::SendRequest problem

CHttpFile::SendRequest problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpdatabasecomquestionannouncement
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    msn92
    wrote on last edited by
    #1

    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?

    M 1 Reply Last reply
    0
    • M msn92

      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?

      M Offline
      M Offline
      msn92
      wrote on last edited by
      #2

      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?

      S 1 Reply Last reply
      0
      • M msn92

        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?

        S Offline
        S Offline
        Swapnil Shah
        wrote on last edited by
        #3

        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

        M 1 Reply Last reply
        0
        • S Swapnil Shah

          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

          M Offline
          M Offline
          msn92
          wrote on last edited by
          #4

          Thanks alot for your reply Swapnil. CHttpFile::QueryInfoStatusCode is very helpful, thank you! :) That's what I did. I used CHttpFile::Read, and it didn't look like a right response. Looks like I'm sending wrong headers and/or post data.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups