hôm nay tôi đã thử một cái gì đó bằng cách sử dụng 'lib cURL' khi tôi nhận được lỗi lạ này, tôi không thể tìm thấy một giải pháp cho điều này, bạn có thể giúp tôi tìm ra?php cURL - Yêu cầu phải được chunked hoặc có chiều dài nội dung
<?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;
?>
Vì vậy, lỗi trở lại của tôi là:
HTTP/1.1 302 Tìm thấy Cache-Control: private Content-Type: text/html; charset = utf-8 Địa điểm: /Login/Default.aspx?ReturnUrl=%2fMy%2fPrivateMessage.aspx%3fRecipientID%3d20815603 & RecipientID = 20815603 Máy chủ: Microsoft-IIS/7.0 Set-Cookie: rbx-ip =; path = /; HttpOnly Set-Cookie: RBXSource = rbx_acquisition_time = 10/14/2011 3:32:12 PM & rbx_acquisition_referrer = http: //www.website.com/My/PrivateMessage.aspx? RecipientID = 20815603 & rbx_medium = Trực tiếp & rbx_source = www .website.com & rbx_campaign = & rbx_send_info = 0; hết hạn = CN, ngày 13 tháng 11 năm 2011 21:32:12 GMT; path =/X-AspNet-Phiên bản: 4.0.30319 X-Powered-By: ASP.NET P3P: CP = "CAO DSP COR CURa ADMa DEVA CỦA CHÚNG TÔI IND PHY ONL UNI COM NAV VÀO NGÀY PRE" Ngày: Thứ Sáu, ngày 14 tháng 10 năm 2011 20:32:12 GMT Content-Length: 224 HTTP/1.1 411 Độ dài nội dung bắt buộc-Type: text/html; charset = us-ascii Máy chủ: Microsoft-HTTPAPI/2.0 Ngày: Thứ Sáu, 14 tháng 10 năm 2011 20:32:12 GMT Kết nối: đóng Nội dung dài: 344
Thời lượng bắt buộc Lỗi HTTP 411. Yêu cầu phải được chunked hoặc có Thời lượng nội dung.
Vì vậy, vấn đề của tôi là "Yêu cầu phải được chunked hoặc có độ dài nội dung". Bài đăng của tôi được thực hiện bằng cách tham khảo bài đăng trên trình duyệt bằng cách sử dụng 'Tiêu đề HTTP Trực tiếp' (Mozila)
Nếu tôi nhận xét dữ liệu giây & mở/đăng hoạt động tốt. Dữ liệu giây và mở/đăng là vấn đề.
Ai đó có thể giúp tôi không? Cảm ơn bạn đã đọc.
FYI: CURLOPT_CUSTOMREQUEST dành cho các yêu cầu KHÁC so với đăng/nhận. Đó là khi bạn cần làm HEAD, PUT, v.v ... bằng cách sử dụng CURLOPT_POST đã đặt curl vào chế độ đăng bài. –