cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Multipart, xml request (newbie question)

From: Erik Mellström <erik.mellstrom_at_gmail.com>
Date: Tue, 26 Jul 2005 17:58:15 +0200

Hi guys!

Spent many hours on this one without success. Guess there is a simple
answer, please help.

Want to use cURL to submit the following information (and other similar
codes) to an http server (this is an example from the manual):

"POST /ClientHTTPSession HTTP/1.1
Content-Type: multipart; boundary=123456f
Content-Length:233
Expect: 100-continue
Connection: close
Host: server.com

--123456f
Content-Disposition: form-data; name="Request"

<?xml version="1.0" encoding="ISO-8859-1"?>
<LogInRequest>
<CustomerID>123456</CustomerId>
<UserID>Kalle</UserID>
<Password>Kalle 123</Password>
</LogInRequest>

--123456f--"

This should return some code, such as (also from the manual):

"HTTP/1.1 200 OK
Content-type: text/html
ResponseCode: 4000 Invalid password!"

I try to use something like:

"$request = <<<STRING
<?xml version="1.0" encoding="ISO-8859-1"?>
<LogInRequest>
<CustomerID>123456</CustomerId>
<UserID>Kalle</UserID>
<Password>Kalle 123</Password>
</LogInRequest>
STRING;

$header = array(
    "Content-Type: multipart; boundary=123456f",
    "Content-Length:233",
    "Expect: 100-continue",
    "Connection: close",
    "Host: server.com");

$con = curl_init();

curl_setopt($con, CURLOPT_URL, "http://server.com:4836"); //port 4836
curl_setopt($con, CURLOPT_RETURNTRANSFER, 1);

//curl_setopt($con, CURLOPT_HEADER, 0);
curl_setopt($con, CURLOPT_POST, 1);
curl_setopt($con, CURLOPT_HTTPHEADER, $header);
curl_setopt($con, CURLOPT_POSTFIELDS, "Request=".urlencode($request));

$string = curl_exec($con);
$errno = curl_errno($con);
if ($errno)
    echo "Error: ".$errno;

curl_close($con);

echo strlen($string).": ".$string;"

I have tried many different settings with CURLOPTs, but nothing seem to
work. The most common results are
- "HTTP Error 405. 405 Method Not Allowed. The method specified in the
Request Line is not allowed for the resource identified by the request.
Please ensure that you have the proper MIME type set up for the resource
you are requesting."
- a space and a linebreak [strlen($string) = 3].
- nothing; the scripts stops after about 30 seconds, the browser still
displaying last page visited.

I guess it's easier for you guys to correct me than for me to explain
all different compinations of CURLOPTs I've tried. What's wrong?

I also wonder how they calculate the "Content-Length: 233" value. What's
included in those 233 bytes? strlen($request) is smaller than 200. Guess
I can figure that one out myself though.

Thanks in advance!

/Erik
Received on 2005-07-26