如何向HTTP标头添加内容?

时间:2013-12-21 15:00:45

标签: php curl

我是PHP / cURL的新手,我需要将这些内容元素添加到CURLOPT_HTTPHEADER

Content-Type: application/octet-stream
Content-Disposition: form-data; name="media[]"; filename="http://www.example.com/pic/test.jpg"

PHP:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: ' . $this->get_DST($status)));

curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'status='.rawurlencode($status);
curl_setopt($ch, CURLOPT_URL, $url);

2 个答案:

答案 0 :(得分:0)

$headers = array(
    'Authorization: ' . $this->get_DST($status),
    'Content-Type: application/octet-stream',
    'Content-Disposition: form-data; name="media[]"; filename="http://www.example.com/pic/test.jpg"'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

http://www.php.net/manual/en/function.curl-setopt.php

答案 1 :(得分:0)

$headers = array( 'Authorization: ' . $this->get_DST($status),
                  'Content-Type: application/octet-stream',
                  'Content-Disposition: form-data; name="media[]"; filename="http://www.example.com/pic/test.jpg'
                 );
curl_setopt ($ch, CURLOPT_HTTPHEADER,$headers);