cURL / Mailing Lists / curl-library / Single Mail

curl-library

Translate a curl command

From: Juan David Palomino <jpalomino_at_tcpsi.es>
Date: Wed, 21 Apr 2004 12:52:34 +0200

I want to translate the next command to libcurl:
curl -v -F fichName=@peticion.xml http://10.95.8.250/monitor/termPinger.php

The target is to send a xml (multipart) and get the answer.
The best try i do is:
curl = curl_easy_init();
 if(curl) {
     curl_easy_setopt(curl, CURLOPT_URL, "http://10.95.8.250/monitor/termPinger.php");
  curl_easy_setopt(curl, CURLOPT_VERBOSE, true);

  struct curl_httppost* post=NULL;
  struct curl_httppost* last=NULL;
  struct curl_slist *headers=NULL;
     headers = curl_slist_append(headers, "Content-Type: text/xml");
  
     curl_formadd(&post, &last,
  CURLFORM_COPYNAME, "logotype-image",
  CURLFORM_FILECONTENT, "peticion.xml",
  CURLFORM_CONTENTHEADER, headers,
  CURLFORM_END);

  curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
  res = curl_easy_perform(curl); /* post away! */
 
  curl_formfree(post); /* free post */
  curl_slist_free_all(headers); /* free custom header list */
  curl_easy_cleanup(curl);

 }

the output of the command is:
* About to connect() to 10.95.8.250 port 80
* Connected to 10.95.8.250 (10.95.8.250) port 80
> POST /monitor/termPinger.php HTTP/1.1
User-Agent: curl/7.11.1 (hppa1.1-hp-hpux11.00) libcurl/7.11.1 zlib/1.1.4
Host: 10.95.8.250
Pragma: no-cache
Accept: */*
Content-Length: 331
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------800aaf0ab511

< HTTP/1.1 200 OK
< Date: Wed, 21 Apr 2004 08:55:50 GMT
< Server: Apache/1.3.12 (Unix) PHP/4.1.0
< X-Powered-By: PHP/4.1.0
< Transfer-Encoding: chunked
< Content-Type: text/xml
<?xml version="1.0" encoding="iso-8859-1"?>
<Message>
<ResponsePingATM Type="Status" Order="1" PhoneNumber="899999999" Response="1">
</ResponsePingATM>
</Message>* Connection #0 left intact
* Closing connection #0

and the output of libcurl is:
* About to connect() to 10.95.8.250 port 80
* Connected to 10.95.8.250 (10.95.8.250) port 80
> POST /monitor/termPinger.php HTTP/1.1
Host: 10.95.8.250
Pragma: no-cache
Accept: */*
Content-Length: 309
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------d57baa48ac5f

< HTTP/1.1 200 OK
< Date: Wed, 21 Apr 2004 10:47:45 GMT
< Server: Apache/1.3.12 (Unix) PHP/4.1.0
< X-Powered-By: PHP/4.1.0
< Transfer-Encoding: chunked
< Content-Type: text/xml
<?xml version="1.0" encoding="iso-8859-1"?>
<Error date="21-04-2004 12:04:47">
<Text>No se recibió el fichero con la petición</Text>
</Error>
* Connection #0 left intact
* Closing connection #0

Help please. Thanks to all.
Received on 2004-04-21