cURL / Mailing Lists / curl-library / Single Mail

curl-library

SOAP Response into variable -- Need help with write function

From: Matthew McNaughton <mamcnaughton_at_gmail.com>
Date: Fri, 12 Nov 2010 05:43:07 -0500

Greetings again libcurl community,
I'm having an issue with my read function. The requirement behind the
function below is that it needs to take two arguments. The first is a
string that contains a SOAP request, while the second is the variable I
need to wrt In response I need to write the SOAP response to the
variable outStr. Assume that outStr is sufficiently large to hold the
message.

size_t write_data(void *ptr, size_t size, size_t nmeb, void *stream)
{
    strcat(((char *) stream), ((char *) ptr))
    return size*nmeb;
}

char * sendMessage (const char * inStr, char * outStr) {

    struct curl_slist *header = NULL;
    header = curl_slist_append (header, "Content-Type:text/xml");
    header = curl_slist_append (header, "SOAPAction: myur1");
    header = curl_slist_append (header, "Transfer-Encoding: chunked");
    header = curl_slist_append (header, "Expect:");
    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL, CLURL);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, inStr);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
write_data); //Gets data to be written to file
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, outStr); //Writes
result to file
 result to file
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE,
(curl_off_t)-1);
        curl_easy_setopt(curl, CURLOPT_VERBOSE,1L);
        res = curl_easy_perform(curl); //Returns 0 if everything
performed ok
        curl_easy_cleanup(curl);
        if (res == 0)
            return (char *)1;
    }
    else
        perror("Error initializing curl connection: ");
    return (char *)0;
        
}

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