We help IT Professionals succeed at work.

How to use POST method to send data to server by using HTTP connection in C++

Mobinex
Mobinex asked
on
1,028 Views
Last Modified: 2010-05-18
Hi Experts,
I am working with C++ client that need to send and get data in XML format from JAVA server.
Can you help me with some examples or suggestion about how to use POST method to POST xml content data to Server by using HTTP connection?
It means we don't use to send xml data as:http://myserver.com?xmlData=<>.....</>
we need to use POST to post xml data content to server.

Thank in advace!

Comment
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2009

Commented:
I would suggest to take a look at cURL :

        http://curl.haxx.se/

which can do the HTTP part for you (POST an XML message).

If you also need a good XML library, I suggest libxml :

        http://xmlsoft.org/

You can use it for creating and parsing XML messages.

Both are free.

Author

Commented:
static TCHAR hdrs[] =
      _T("Content-Type: application/x-www-form-urlencoded");
   static TCHAR frmdata[] =
      _T("name=John+Doe&userid=hithere&other=P%26Q");
  static LPSTR accept[2]={"*/*", NULL};

   // for clarity, error-checking has been removed
   HINTERNET hSession = InternetOpen("MyAgent",
      INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
   HINTERNET hConnect = InternetConnect(hSession, _T("ServerNameHere"),
      INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
   HINTERNET hRequest = HttpOpenRequest(hConnect, "POST",
      _T("FormActionHere"), NULL, NULL, accept, 0, 1);
   HttpSendRequest(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata));
   // close any valid internet-handles
                        
Can you explain what _T("FormActionHere")?

I have a xml contents data, or simple is a string data.
I want to post this to server (no arguments),

Can you help me with a example for this?
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.