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 02:45:29 -0500

 
Hi Issac,

Even after putting the changes (below) as suggested by you, I am not
able to get anything from server.

1)Create a header pointer and append the header type.
2)set the header to your handle
3)call perform();

Could you or anyone please suggest anything else?

Now, my code looks like:

************************************************************************
*******************

                mCurl = curl_easy_init();

                struct curl_slist *headers = NULL; //note the pointer
here
                headers = curl_slist_append(headers, "Content-Type:
Multipart/Related");
                headers = curl_slist_append(headers, "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());
                errNum = curl_easy_setopt(mCurl, CURLOPT_USERPWD,
"administrator:collect_at_234");

                char headerfilename[FILENAME_MAX] = "head.out";
                FILE *headerfile;
                errNum = curl_easy_setopt(mCurl,
CURLOPT_WRITEFUNCTION, &write_data);
                
                headerfile = fopen(headerfilename,"w");
                if (headerfile == NULL) {
                        curl_easy_cleanup(mCurl);
                        return;
                }
                errNum = curl_easy_setopt(mCurl, CURLOPT_WRITEHEADER
,headerfile);

                curl_easy_perform(mCurl);
                if (CURLE_OK != errNum) {
                        exit(EXIT_FAILURE);
                }

                fclose(headerfile);

                curl_easy_cleanup(mCurl);

& strHttpContent is initialized 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/window
s/EventLog</w:ResourceURI><a:ReplyTo><a:Address
s:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2004/08/addressing
/role/anonymous</a:Address></a:ReplyTo><a:Action
s:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2004/08/eventing/S
ubscribe</a:Action><w:MaxEnvelopeSize
s:mustUnderstand="true">153600</w:MaxEnvelopeSize><a:MessageID>uuid:0f3d
7fd4-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:Operation
Timeout></s:Header><s:Body><e:Subscribe><e:Delivery
Mode="http://schemas.dmtf.org/wbem/wsman/1/wsman/Pull"><w:Heartbeats>PT2
000.000S</w:Heartbeats><w:Locale
xml:lang="en-US"/><w:ContentEncoding>UTF-8</w:ContentEncoding></e:Delive
ry><w:Filter
Dialect="http://schemas.microsoft.com/win/2004/08/events/eventquery"><Qu
eryList><Query Id="0"><Select Path="Application">*</Select><Select
Path="System">*</Select><Select
Path="Security">*</Select></Query></QueryList></w:Filter><w:SendBookmark
s/></e:Subscribe></s:Body></s:Envelope>"

Regards.
Nitin

On 12/15/2009 08:32 AM, nitin.mittal_at_rsa.com wrote:
> So, I added the line suggested by you in my code.& post modification,
> my code looks like:
>
>
>
************************************************************************
> ************************
> struct curl_slist SOAPaction;
> struct curl_slist content_type;
>
> memset(&SOAPaction, 0, sizeof(SOAPaction));
> memset(&content_type, 0, sizeof(content_type));
>
> content_type.data = "Content-Type: text/xml";
> SOAPaction.data = "SOAPAction: \"\""; /* Empty SOAPAction is the
ID-WSF
> (and SAML?) standard */
>
> SOAPaction.next =&content_type; //curl_slist_append(3)
>
> mCurl = curl_easy_init();
> 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_USERPWD, "administrator:collect_at_234");
>
> //set size of postfield data
> curl_easy_setopt(mCurl, CURLOPT_POSTFIELDSIZE,
strHttpContent.length());
>
> //pass headers
> curl_easy_setopt(mCurl, CURLOPT_HTTPHEADER,&SOAPaction);

Where is the curl header append function for your code???
I think its safe and less error prone if you follow the standard.
Do this:

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

SOAP is just xml over http so its crucial that if you will use libcurl
you use the standard of using the pointer to curl_slist layout above so
you can pass the right headers with post.

1)Create a header pointer and append the header type.
2)set the header to your handle
3)call perform();

-------------------------------------------------------------------
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-16