cURL / Mailing Lists / curl-library / Single Mail

curl-library

Regarding creating a handle to the SOAP string response

From: abhishek Kalapatapu <abhisrk_at_gmail.com>
Date: Thu, 15 Sep 2011 23:36:47 -0700

Hello,

I am trying to send a SOAP request to a webservice and receive the response
back using C. I was directed to an example of "simplepost.c" and using that,
I am able to send and print a SOAP response back from a web service on my
command line. But instead of printing the response on the screen, I want a
handle to the response string, so that I am able to extract the values
inside the SOAP tags. I have the following send and receive program written,
but i am not able to receive proper response, which means either there is
problem in sending or receiving. If any one can help me locate how exactly
can I achieve, what i want, it would be really helpful. Thanks in advance.

My code:

#include <stdio.h>
#include <string.h>
#include <curl/curl.h>

/* Auxiliary function that waits on the socket. */

int main(void)
{
  CURL *curl;
  CURLcode res;
  /* Minimalistic http request */
  const char *request = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"xmlns:xsd=\"
http://www.w3.org/2001/XMLSchema\"xmlns:tns=\"
http://ThermodynamicProperties/\"><S:Body> <tns:getSpeciesInformation>
<speciesSymbol>CO2</speciesSymbol> <phase>GAS</phase>
</tns:getSpeciesInformation> </S:Body> </S:Envelope>";

size_t iolen;

  struct curl_slist *headerlist=NULL;
  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "
http://thermo.sdsu.edu/servlet/ThermodynamicProperties/ThermodynamicPropertiesService
");
    /* Do not do the transfer - only connect to host */
    curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);

    res = curl_easy_perform(curl);

    if(CURLE_OK != res)
    {
      printf("Error: %s\n", strerror(res));
      return 1;
    }

curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
curl_easy_setopt(curl, CURLOPT_POST, 1);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);

    puts("Sending request.");
    /* Send the request. Real applications should check the iolen
     * to see if all the request has been sent */
    res = curl_easy_send(curl,request, strlen(request), &iolen);

    if(CURLE_OK != res)
    {
      printf("Error: %s\n", curl_easy_strerror(res));
      return 1;
    }
    puts("Reading response.");

    /* read the response */

printf("ok1 \n");
  char buf[10240];
  res = curl_easy_recv(curl, buf, 10240, &iolen);
 printf("ok2 \n");
      if(CURLE_OK != res)

 {
printf("Error: %s\n", strerror(res));

   }
else{ printf("data %s \n", buf);

    }

    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  return 0;
}

The response I am getting is:
Sending request.
Reading response.
ok1
ok2
Error: .lib section in a.out corrupted

-- 
*Cheers*
*Abhishek Kalapatapu*

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-09-16