今日私はこの奇妙なエラーが発生したときに 'lib cURL'を使って何かを試していましたが、解決策が見つかりませんでした。だから、php cURL - 要求がチャンクされているかコンテンツの長さがある
<?php
set_time_limit(0);
class cURL
{
var $content;
var $cookie;
var $headers = array();
var $ch;
var $data;
var $info;
var $httpcode;
var $proxy_ip;
var $proxy_port;
var $cookie_f;
function __construct($cookie = '')
{
if (!empty($cookie)) {
$this->cookie_f = $cookie;
}
}
function setproxy($proxy)
{
list($ip, $porta) = explode(":", $proxy);
$this->proxy_ip = $ip;
$this->proxy_port = $porta;
}
function setcookie($cookie)
{
$this->cookie = $cookie;
}
function open($type, $url)
{
$this->ch = curl_init();
curl_setopt($this->ch, CURLOPT_URL, $url);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->ch, CURLOPT_HEADER, true);
//curl_setopt($this->ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded", "Content-length: 216"));
curl_setopt($this->ch, CURLOPT_ENCODING, "");
curl_setopt($this->ch, CURLOPT_COOKIEFILE, getcwd() . '/cookies.cookie');
curl_setopt($this->ch, CURLOPT_COOKIEJAR, getcwd() . '/cookies.cookie');
curl_setopt($this->ch, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pt-BR; rv:1.9.2.18) Gecko/20110614 Firefox/3.6.18");
if (strtolower($type) == 'post') {
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($this->ch, CURLOPT_POST, 1);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->data);
curl_setopt($this->ch, CURLOPT_HEADER, true);
}
$this->content = curl_exec($this->ch);
curl_close($this->ch);
return $this->content;
}
}
?>
<?php
$curll = New cURL;
$curll ->setCookie = "cookies.cookie";
$curll ->data = "username=user&password=pass&IsSyncUp=&FacebookAssociation=&SNAccessToken=";
$curll ->open("POST", "http://www.website.com");
$curll ->data = '__EVENTTARGET=ctl00$ctl00$cphRoblox$cphMyRobloxContent$lbSend&ctl00$ctl00$cphRoblox$cphMyRobloxContent$rbxMessageEditor$txtSubject=AAAAAAAAA&ctl00$ctl00$cphRoblox$cphMyRobloxContent$rbxMessageEditor$txtBody=BBBBBBBBB';
$curll ->open("POST", "http://www.website.com/My/PrivateMessage.aspx?RecipientID=20815603");
echo $curll ->content;
?>
、私の返されたエラー:
HTTP/1.1 302発見のCache-Control:プライベートのContent-Type:text/htmlの。 charset = utf-8場所:/Login/Default.aspx?ReturnUrl=%2fMy%2fPrivateMessage.aspx%3fRecipientID%3d20815603 & RecipientID = 20815603サーバー:Microsoft-IIS/7.0 Set-Cookie:rbx-ip =;パス= /; http://www.website.com/My/PrivateMessage.aspx?RecipientID = 20815603 & rbx_medium =直接& rbx_source = www .website.com & rbx_campaign = & rbx_send_info = 0; expires = Sun、2011年11月13日21:32:12 GMT;パス=/X-AspNet-バージョン:4.0.30319 X-Powered-By:ASP.NET P3P:CP = "CAO DSP COR CURA ADAMA DEVAのIND PHI ON UNI COM NAV INT DEM PRE"日付:2011年10月14日20:32:12 GMT Content-Length:224 HTTP/1.1 411長さが必要です。Content-Type:text/html; charset = us-asciiサーバー:Microsoft-HTTPAPI/2.0日付:2011年10月14日金曜日20:32:12 GMT接続:閉じるコンテンツの長さ:344
長さが必要です HTTPエラー411.要求にはチャンクが必要です。コンテンツの長さ。
私の問題は「要求がチャンクされているかコンテンツの長さがある」ということでした。 POSTは「ライブHTTPヘッダー」(Mozila)を使用してブラウザの投稿に相談しました
私は秒のデータ&を開いて投稿するとうまくいきます。 秒データとオープン/ポストが問題でした。
誰かが私を助けることができますか? 読んでいただきありがとうございます。
FYI:CURLOPT_CUSTOMREQUESTは、投稿/取得以外のリクエストです。あなたがHEAD、PUTなどをする必要があるときです.CURLOPT_POSTを使用すると、既にカールがポストモードになります。 –