Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all,

I want to create a post request and send it to server using libCURL can anyone help me in that.
If this is my sample request

<GetCapabilities version="1.0.0" service="WCS">
<section>/WCS_Capabilities/Capability</section>
</GetCapabilities>

how am I suppose to set the xml elements and their attributes value in the curl options.

Please help, this is really important.
Posted
Comments
AsthaS 6-Dec-13 5:20am    
Please someone help me out in this.

1 solution

The simplest way is three calls to curl_easy_setopt

CURLOPT_POST tells the library that you're going to do a post.

CURLOPT_POSTFIELDS tells the library that this is a pointer to the data that you want to send in exactly the form the server expects it. It's up to you to make sure that this format is correct. If you're using an XML expecting webservice you get to form the XML, libCurl won't help.

CURLOPT_POSTFIELDSIZE tells the library the size of the data you want sent.

Alternatively you can read the curl_easy_setopt[^] docs and see how you can use a callback to form the data - but whether you need that depends on how you interact with the server.
 
Share this answer
 
Comments
AsthaS 9-Dec-13 3:16am    
Hi..
Thanks for the reply, But my problem is still there-
I am using the following code :

string xmlString = "<getcapabilities service="\"WCS\"" version="\"1.0.0\"" xmlns="\"http://www.opengis.net/wcs\"/">";

curl_easy_setopt(m_ptrCurlHandle, CURLOPT_URL,"http://172.21.134.150:8080/geoserver/wcs");
curl_easy_setopt(m_ptrCurlHandle, CURLOPT_POST, 1);
curl_easy_setopt(m_ptrCurlHandle, CURLOPT_POSTFIELDS, xmlString.c_str());
curl_easy_setopt(m_ptrCurlHandle, CURLOPT_POSTFIELDSIZE, xmlString.length());
slist = curl_slist_append(NULL, "Content-Type: text/xml; charset=utf-8");
curl_easy_setopt(m_ptrCurlHandle, CURLOPT_HTTPHEADER, slist);
curl_easy_perform(m_ptrCurlHandle);
curl_easy_cleanup(m_ptrCurlHandle);

Where my desired xml post request is
< GetCapabilities service="WCS" version="1.0.0" xmlns="http://www.opengis.net/wcs"/>

But every time is execute the code it gives me -

< ?xml version="1.0" encoding="UTF-8"?>
< ows:ExceptionReport version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/ows http://172.21.134.150:8080/geoserver/schemas/ows/1.0.0/owsExceptionReport.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows">
< ows:Exception exceptionCode="NoApplicableCode">
<ows:exceptiontext>org.xmlpull.v1.XmlPullParserException: only whitespace content allowed before start tag and not \u0 (position: START_DOCUMENT seen \u0... @1:1)
only whitespace content allowed before start tag and not \u0 (position: START_DOCUMENT seen \u0... @1:1)



as the response. I really don't have the clue what am I doing wrong.
Please help.
Aescleal 9-Dec-13 4:35am    
Not a clue either - looks like the server's complaining about extra or unexpected whitespace. That might be you're sending an unexpected character encoding or even something like the server's XML parser not understanding the space between your request's opening < and tag name.
ranjan biswas 2023 16-Mar-24 6:05am    
ok

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900