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. Posting data to web

Posting data to web

Scheduled Pinned Locked Moved C / C++ / MFC
helpcom
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.
  • R Offline
    R Offline
    Rahim Rattani
    wrote on last edited by
    #1

    Currently I am using the following piece of code to post data to a website HRESULT hResult; hResult = HttpRequest.CreateInstance("Microsoft.XMLHTTP"); if ( FAILED(hResult) ) return bRetVal; //error VARIANT vAsync; vAsync.vt = VT_BOOL; vAsync.boolVal = FALSE; VARIANT vUser; vUser.vt = VT_BSTR; vUser.bstrVal = NULL; VARIANT vPassword; vPassword.vt = VT_BSTR; vPassword.bstrVal = NULL; HttpRequest->open("POST", "http://web.cgi", vAsync, vUser, vPassword); HttpRequest->setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); CString szRequest = "static=1&entry_id=328&name=R&email=r@r.com"; VARIANT vRequest; vRequest.vt = VT_BSTR; vRequest.bstrVal = szRequest.AllocSysString(); //Send Http Request HttpRequest->send(vRequest); //Read response and status // m_lHttpStatus = HttpRequest->status; m_szHttpStatusText = (char*)HttpRequest->statusText; _bstr_t bsResponse = HttpRequest->responseText; Everything is going fine the data is posted through the code and OK is retutrned. But when i view the website the data is not there. It seemd that the data is not posted to the web. Am i doing everything right- Is there any opther way to do so. PLease help me out.

    T 1 Reply Last reply
    0
    • R Rahim Rattani

      Currently I am using the following piece of code to post data to a website HRESULT hResult; hResult = HttpRequest.CreateInstance("Microsoft.XMLHTTP"); if ( FAILED(hResult) ) return bRetVal; //error VARIANT vAsync; vAsync.vt = VT_BOOL; vAsync.boolVal = FALSE; VARIANT vUser; vUser.vt = VT_BSTR; vUser.bstrVal = NULL; VARIANT vPassword; vPassword.vt = VT_BSTR; vPassword.bstrVal = NULL; HttpRequest->open("POST", "http://web.cgi", vAsync, vUser, vPassword); HttpRequest->setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); CString szRequest = "static=1&entry_id=328&name=R&email=r@r.com"; VARIANT vRequest; vRequest.vt = VT_BSTR; vRequest.bstrVal = szRequest.AllocSysString(); //Send Http Request HttpRequest->send(vRequest); //Read response and status // m_lHttpStatus = HttpRequest->status; m_szHttpStatusText = (char*)HttpRequest->statusText; _bstr_t bsResponse = HttpRequest->responseText; Everything is going fine the data is posted through the code and OK is retutrned. But when i view the website the data is not there. It seemd that the data is not posted to the web. Am i doing everything right- Is there any opther way to do so. PLease help me out.

      T Offline
      T Offline
      ThatsAlok
      wrote on last edited by
      #2

      IS your Webserver provide support for Posting data from application. Returning OK means that The Url you requested is Found,this Ok dosn't tell any thing about the your data posting is successful. data posting always come witha html file in return,try to read that file,it may contain possible error description ----------------------------- "I Think It Will Help" ----------------------------- Alok Gupta visit me at http://www.thisisalok.tk

      R 1 Reply Last reply
      0
      • T ThatsAlok

        IS your Webserver provide support for Posting data from application. Returning OK means that The Url you requested is Found,this Ok dosn't tell any thing about the your data posting is successful. data posting always come witha html file in return,try to read that file,it may contain possible error description ----------------------------- "I Think It Will Help" ----------------------------- Alok Gupta visit me at http://www.thisisalok.tk

        R Offline
        R Offline
        Rahim Rattani
        wrote on last edited by
        #3

        _bstr_t bsResponse = HttpRequest->responseText; The above line contains the contents of the HTML Page. But the problem is that It only contains first few lines. The tag is not even complete in the string. Dont know how to get it. Can it be done thru some other way.

        T 1 Reply Last reply
        0
        • R Rahim Rattani

          _bstr_t bsResponse = HttpRequest->responseText; The above line contains the contents of the HTML Page. But the problem is that It only contains first few lines. The tag is not even complete in the string. Dont know how to get it. Can it be done thru some other way.

          T Offline
          T Offline
          ThatsAlok
          wrote on last edited by
          #4

          Yeah Buddy, ther is very good Class named AmHttpSocket or amHttpFile in Internet Section , it hink that will help you out. or ucan use InternetReadFile Api's if you dunno want ot use MFC based CInterneSession Class. ----------------------------- "I Think It Will Help" ----------------------------- Alok Gupta visit me at http://www.thisisalok.tk

          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