Discussion:
curl with basic authorization and multipart/form-data
Radek Krejča
2014-08-05 16:42:29 UTC
Permalink
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Radek Krejča
2014-08-05 18:33:59 UTC
Permalink
Sorry for my previous post, it was my mistake.

But I have second question. I am trying to send form over curl, where are many fields and all have to be present. And two fields are input type=file, but I need it to be empty value. I simply need this:

Content-Disposition: form-data; name=" text_file"; filename=""
Content-Type: application/octet-stream

How can I manage it? If I use:

$postdata["text_file"] = '@;type=application/octet-stream';

Nothing hapens. I must be existed file or curl do nothing.

Thank you for advice.

Radek
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...