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

curl-and-php

multipart/form-data problem

From: Anders Berg <anders_at_scangen.se>
Date: Sun, 12 Jun 2011 16:55:38 +0200

I am trying to send the following (output from Live HTTP headers) with curl/php:

Content-Type: multipart/form-data; boundary=---------------------------237301273958
Content-Length: 144
-----------------------------237301273958
Content-Disposition: form-data; name="db"

database1
-----------------------------237301273958--

HTTP/1.1 200 OK

From what I have read curl handles the boundary and content-disposition stuff, and I have also found out that postdata should be sent as an array, not a string. I have tried things like this:

 $postfields = array("db" => "database1");
 $headers = array("Content-Type: multipart/form-data", "Content-Length: 144");

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_HEADER, 0);
 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
 curl_setopt($ch, CURLOPT_REFERER, $referer);
 curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookieFileName");
 curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookieFileName");
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
 $page = curl_exec($ch);

It return the 413 error
Request Entity Too Large The requested resource <phpfile> does not allow request data with POST requests, or the amount of data provided in the request exceeds the capacity limit.

I have tried different values for Content-Length and also omitted it, with the same result. Obviously Content-Length include the boundary etc data, but how do I know what value I should send as length when curl handles the boundary stuff automagically?

Note that it isn't a file I am sending. The page still wants multipart/form-data as Content-Type.

Thanks for any input. Sorry if this is newbie stuff.

/A

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2011-06-12