[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1009
  • Last Modified:

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

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!

0
Mobinex
Asked:
Mobinex
1 Solution
 
OnegaZhangCommented:
Read the MSDN
http://support.microsoft.com/kb/q165298/
How to simulate a Form POST request by using WinInet
0
 
Infinity08Commented:
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.
0
 
MobinexAuthor 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?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now