curl with basic authorization and multipart/form-data
| From: | Radek Krejča | Date: | Tue, 05 Aug 2014 16:42:29 +0000 |
| Subject: | curl with basic authorization and multipart/form-data | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-323716@lists.php.net to get a copy of this message | ||
Hello,
I have following script:
<?
$ch = curl_init();
$headers = array(
'Authorization: Basic '. base64_encode("user:pass")
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, 'https://someserver/?action=add&do=addForm-submit');
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; FreeBSD amd64; rv:9..0.1)
Gecko/20100101 Firefox/9.0.1");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("var" => "",
"save"=>'Add to queue!'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, 'https://someserver/?action=add');
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookie.txt");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
print_r( $output);
?>
But it doesnt work. I got Internal server error. If I add 'Content-Type:text/html, to headers
array, I am succesfully authorized without problems, but call isnt multipart/form-data and form isnt
sended. I tried comment curl_setopt($ch, CURLOPT_POST, 1); too, but without success.
How I can combine authorization and correct encoding?
Thank you
Radek