1
我收到400 http_code錯誤,當我發送一個Ajax請求與CURL下面是我的代碼。如何使用PHP CURL模擬Ajax請求?
$header = array(
"Accept : application/json, text/javascript, */*; q=0.01",
"Accept-Encoding : gzip, deflate",
"Accept-Language : en-US,en;q=0.5",
"Content-Type : application/json; charset=UTF-8",
"Host : https://some.com",
"Referer : https://some.com/dashboard/reports",
"X-Requested-With : XMLHttpRequest"
);
$c = curl_init('https://domain.com/report.php');
//curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($c, CURLOPT_VERBOSE, true);
curl_setopt($c, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $data_url);
curl_setopt($c, CURLOPT_HTTPHEADER, $header);
//curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Requested-With: XMLHttpRequest"));
curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_jar);
$page = curl_exec($c);
$httpcode = curl_getinfo($c);
//我在做捲髮要求
Array
(
[url] => some_url
[content_type] =>
[http_code] => 400
[header_size] => 70
[request_size] => 935
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.205562
[namelookup_time] => 0.000132
[connect_time] => 0.032866
[pretransfer_time] => 0.170225
[size_upload] => 272
[size_download] => 0
[speed_download] => 0
[speed_upload] => 1323
[download_content_length] => 0
[upload_content_length] => 272
[starttransfer_time] => 0.205498
[redirect_time] => 0
[certinfo] => Array
(
)
[primary_ip] => 66.35.58.70
[primary_port] => 443
[local_ip] => 198.1.92.85
[local_port] => 53627
[redirect_url] =>
)
////
'400'表示這是一個不好的請求。找出什麼是壞的。也許是一個壞頭? – Halcyon
是的,你是正確的,這是客戶端錯誤,但如果我沒有設置標題,它給了500 http_code,我也嘗試了很多組合,使頭... :) –
你能縮小你的問題的一個最小的例子嗎? – cmbarbu