使用curl发送Content-length标头的问题 [英] Problem with curl to send Content-length header
本文介绍了使用curl发送Content-length标头的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要上传文件到wupload
这里是我的功能
i need to upload files to wupload here is my function
public function doPost($link, $postfields = '', $cookie = '', $ref = '', $nobody = false, $upload = false, $header = true, $headers = "") {
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if ($header)
curl_setopt($ch, CURLOPT_HEADER, 1);
if ($headers)
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_REFERER, $ref);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
if ($postfields) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
}
if ($cookie) {
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
}
$log = fopen("log.txt", "w+");
curl_setopt($ch, CURLOPT_STDERR, $log);
if ($upload)
curl_setopt($ch, CURLOPT_UPLOAD, true);
$page = curl_exec($ch);
curl_close($ch);
fclose($log);
return($page);
}
我尝试拨打电话
$result = doPost("http://www.wupload.com/file-manager/list", '', $this->upcookies, "http://www.wupload.com/", false);
preg_match("/_uploadServerHostname = '(s[0-9]*.wupload.com)'/i", $result, $matches);
$server = $matches[1];
$post = array();
$post['files[]'] = "@$filelocation";
$headers = array('Content-Type: application/octet-stream','Content-length: ' . filesize($filelocation));
$page = $this->doPost($server, $post, $this->upcookies, "http://www.wupload.com", false, true, true, $headers);
,结果为
HTTP/1.1 411 Length Required Server: nginx Date: Sun, 21 Aug 2011 16:10:51 GMT Content-Type: text/html Content-Length: 174 Connection: close
我以为我发送的内容长度,cookie和文件是确定。
更清楚,这里是这个调用的curl日志
i thought i sent the content lenght, cookies and file are ok. to be more clear, here is the curl log for this call
* About to connect() to s206.wupload.com port 80 (#0)
* Trying 78.140.153.43... * connected
* Connected to s206.wupload.com (78.140.153.43) port 80 (#0)
> PUT / HTTP/1.1
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1
Host: s206.wupload.com
Accept: */*
Referer: http://www.wupload.com
Transfer-Encoding: chunked
Cookie: fs_orderFoldersDirection=asc; fs_orderFoldersBy=name; isAffiliate=1; nickname=soussouheros; email=avix%40live.fr; rememberMe=1; PHPSESSID=96aeh7liqt5p4u4d98at7acv71; role=premium; lang=en; visitSourceUrl=http%3A%2F%2Fwupload.com%2F; C:\wamp\www\tuto\brazzo/temp/wu.up
< HTTP/1.1 411 Length Required
< Server: nginx
< Date: Sun, 21 Aug 2011 16:10:51 GMT
< Content-Type: text/html
< Content-Length: 174
< Connection: close
<
* Closing connection #0
推荐答案
curl_setopt($ch, CURLOPT_UPLOAD, true);
这篇关于使用curl发送Content-length标头的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文