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

Posted on 2007-10-13
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:<>.....</>
we need to use POST to post xml data content to server.

Thank in advace!

Question by:Mobinex
    LVL 12

    Accepted Solution

    Read the MSDN
    How to simulate a Form POST request by using WinInet
    LVL 53

    Expert Comment

    I would suggest to take a look at cURL :


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

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


    You can use it for creating and parsing XML messages.

    Both are free.
    LVL 1

    Author Comment

    static TCHAR hdrs[] =
          _T("Content-Type: application/x-www-form-urlencoded");
       static TCHAR frmdata[] =
      static LPSTR accept[2]={"*/*", NULL};

       // for clarity, error-checking has been removed
       HINTERNET hSession = InternetOpen("MyAgent",
       HINTERNET hConnect = InternetConnect(hSession, _T("ServerNameHere"),
       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?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now