cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: CURLOPT_URL returning FALSE

From: <nitin.mittal_at_rsa.com>
Date: Wed, 16 Dec 2009 22:39:19 -0500

On 12/16/2009 05:16 PM, isaacsannithomas_at_gmail.com wrote:

Hi Nitin,

1) Escape the quotes in the strHttpContent. I believe the xml content is

not fed to the SOAP server in its entirety. Escaping the quotes in the
strHttpContent may help.
2) Also test with a PHP script or Java code that the SOAP server is
receiving request properly and sends response.
3)Set the header to "Content-Type: text/xml"
curl_easy_setopt(mCurl, CURLOPT_POSTFIELDS,strHttpContent.c_str());
curl_easy_setopt(mCurl, CURLOPT_POSTFIELDSIZE, strHttpContent.length());
  curl_easy_setopt(mCurl, CURLOPT_HTTPHEADER, headers);
  curl_easy_perform(mCurl);
4) Write the content of the response from curl to a file. Using the
WRITEHEADER will not put the content of the response in the file.
Maintain the WRITEDATA I showed you earlier. It works for me.
5)If not try writing your code in traditional C.

Hi Issac,

Thanks for your continuous support on this issue. I really appreciate
that.

So, after modifications as suggest by you,

now strHttpContent looks like:

std::string strHttpContent="<s:Envelope
xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"
xmlns:a=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\"
xmlns:e=\"http://schemas.xmlsoap.org/ws/2004/08/eventing\"
xmlns:n=\"http://schemas.xmlsoap.org/ws/2004/09/enumeration\"
xmlns:w=\"http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd\"><s:Header><a:
To>http://10.31.251.161:5985/wsman</a:To><w:ResourceURI
s:mustUnderstand=\"true\">http://schemas.microsoft.com/wbem/wsman/1/wind
ows/EventLog</w:ResourceURI><a:ReplyTo><a:Address
s:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2004/08/addressi
ng/role/anonymous</a:Address></a:ReplyTo><a:Action
s:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2004/08/eventing
/Subscribe</a:Action><w:MaxEnvelopeSize
s:mustUnderstand=\"true\">153600</w:MaxEnvelopeSize><a:MessageID>"uuid:0
f3d7fd4-421e-438c-a75a-832d2c85cb58</a:MessageID><w:Locale
xml:lang=\"en-US\" s:mustUnderstand=\"false\" /><w:OptionSet
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><w:Option
Name=\"SubscriptionName\">RSAenVision</w:Option><w:Option
Name=\"ContentFormat\">RenderedText</w:Option><w:Option
Name=\"ReadExistingEvents\" xsi:nil=\"true\"/><w:Option
Name=\"IgnoreChannelError\"
xsi:nil=\"true\"/></w:OptionSet><w:OperationTimeout>PT60.000S</w:Operati
onTimeout></s:Header><s:Body><e:Subscribe><e:Delivery
Mode=\"http://schemas.dmtf.org/wbem/wsman/1/wsman/Pull\"><w:Heartbeats>P
T2000.000S</w:Heartbeats><w:Locale
xml:lang=\"en-US\"/><w:ContentEncoding>UTF-8</w:ContentEncoding></e:Deli
very><w:Filter
Dialect=\"http://schemas.microsoft.com/win/2004/08/events/eventquery\"><
QueryList><Query Id=\"0\"><Select Path=\"Application\">*</Select><Select
Path=\"System\">*</Select><Select
Path=\"Security\">*</Select></Query></QueryList></w:Filter><w:SendBookma
rks/></e:Subscribe></s:Body></s:Envelope>";

& my code looks like:

mCurl = curl_easy_init();

struct curl_slist *headers = NULL; //note the pointer here
headers = curl_slist_append(headers, "Content-Type: text/xml");

curl_easy_setopt(mCurl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(mCurl, CURLOPT_VERBOSE, TRUE);
curl_easy_setopt(mCurl, CURLOPT_URL, "http://10.31.251.161:5985/wsman");
curl_easy_setopt(mCurl, CURLOPT_POST, 1);
curl_easy_setopt(mCurl, CURLOPT_POSTFIELDS, strHttpContent.c_str());
curl_easy_setopt(mCurl, CURLOPT_POSTFIELDSIZE, strHttpContent.length());
curl_easy_setopt(mCurl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_easy_setopt(mCurl, CURLOPT_USERPWD, "administrator:collect_at_234");

FILE * somefile=fopen("somelog.log","w");
curl_easy_setopt(mCurl,CURLOPT_WRITEDATA,somefile);//server response

curl_easy_perform(mCurl);
curl_easy_cleanup(mCurl);

But the output it shows on std::out is:

* About to connect() to 10.31.251.161 port 5985 (#0)
* Trying 10.31.251.161... * connected
* Connected to 10.31.251.161 (10.31.251.161) port 5985 (#0)
* Server auth using Basic with user 'administrator'
> POST /wsman HTTP/1.1
Authorization: Basic YWRtaW5pc3RyYXRvcjpjb2xsZWN0QDIzNA==
Host: 10.31.251.161:5985
Accept: */*
Content-Type: text/xml
Content-Length: 1748
Expect: 100-continue

< HTTP/1.1 100 Continue
< HTTP/1.1 415
< Server: Microsoft-HTTPAPI/2.0
< Date: Fri, 18 Dec 2009 03:42:24 GMT
< Connection: close
< Content-Length: 0
<
* Closing connection #0

& an empty "somelog.log" log file is created, which means that I am
still not getting any response from the server.

Could you please suggest soemthing?

Regards,
Nitin

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2009-12-17