【发布时间】:2014-02-12 18:02:18
【问题描述】:
我有这种情况: 我想使用 curl 向表单发出 PUT 请求,但它不断检索此错误:“发送失败:连接中止”。这是我使用的功能:
function PutCurl($url,$parametros_post){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch,CURLOPT_HEADER,false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_COOKIEJAR,'cookies.txt');
curl_setopt($ch,CURLOPT_COOKIEFILE,'cookies.txt');
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_PUT,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: '.strlen($parametros_post)));
curl_setopt($ch,CURLOPT_POSTFIELDS,$parametros_post);
$result = curl_exec($ch);
$rerror = curl_error($ch);
curl_close($ch);
if ($rerror != ""){
echo '<h3>'.$rerror.'</h3>';
return false;
}
else
return $result;
}
我收到此错误:
在尝试处理请求时:
PUT /textos-del-anuncio/ HTTP/1.0 用户代理:Mozilla/4.0(兼容;MSIE 5.01;Windows NT 5.0) 主持人:www.somesite.com Pragma:无缓存 接受:/ Cookie:PHPSESSID=gkmb7ksi1o82d91rino35ihma3 期望:100-继续 连接:关闭 X-Forwarded-For:IP 通过:1.0 代理+ (v4.00 http://www.proxyplus.cz) 代理授权:基本 a2F2OjNHd3BiK3J3QiE=
遇到以下错误:
* Invalid Request
HTTP 请求的某些方面无效。可能的问题:
* Missing or unknown request method
* Missing URL
* Missing HTTP Identifier (HTTP/1.0)
* Request is too large
* Content-Length missing for POST or PUT requests
* Illegal character in hostname; underscores are not allowed
然后我尝试在标题中设置 Content-Length 并将这一行添加到我的函数中:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: '.strlen($parametros_post)));
但随后我收到“发送失败:连接已中止”错误。
拜托,谁能帮助我。谢谢。
【问题讨论】:
-
那不是你真正的代理用户和密码吗?!
-
您也可以发布 curl 错误代码吗?
-
我在帖子中添加了错误描述。你能帮我吗?