PHP CURL:手动设置内容长度标题

Say I upload a file with PHP, CURL:

$postData = array();

$postData['file_name'] = "test.txt";
$postData['submit'] = "UPLOAD";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData );

Now assume I have to manually set the content-length header.

$headers=array(
     "POST /rest/objects HTTP/1.1",
     'accept: */*',
     "content-length: 0" //instead of 0, how could I get the length of the body from curl?
    )
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); //set headers
$response = curl_exec($ch);

How would I measure the size of the body? (just specifying the filesize as content length doesn't seem to work)

In another example what if the body contains data that is not an actual file. (manually set by postfields) In that situation how would I get the content length of the body?

Thanks for any light shed on this, it appears to be a tough issue.

查看全部
dpvv37755
dpvv37755
2009/12/16 18:50
  • curl
  • http
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复