2014-07-04 156 views
1

當我在CURL在PHP中。與適當的標題和字段,但它會給我錯誤錯誤400錯誤的請求。爲什麼會出現這個錯誤?錯誤400錯誤的請求,當我使用PHP CURL

HTTP/1.0 400 Bad request Cache-Control: no-cache Connection: close Content-Type: text/html 
400 Bad request 
Your browser sent an invalid request. 1 

頭請求

$header[] = "Accept:application/json, text/javascript, */*; q=0.01"; 
$header[]="Accept-Encoding:gzip, deflate"; 
$header[] = "Cache-Control:max-age=0"; 
$header[]= "Accept-Language:en-US,en;q=0.5"; 
$header[] = "Content-Length:37"; 
$header[]="Content-Type:application/x-www-form-urlencoded; charset=UTF-8"; 
$header[]="Cookie:__qca=P0-116849880-1387336057175; __utma=140029553.335591273.1387336057.1389609300.1389617402.102; __utmz=140029553.1389617402.102.89.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); _ga=GA1.2.335591273.1387336057; sgt=id=3380ce36-a139-4845-bd20-5bb3fd4174ec; usr=t=qrthm51g2UyV&s=QtuIYj84zEOR"; 
$header[]="X-Requested-With:XMLHttpRequest"; 

捲曲代碼

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $request_url); 
curl_setopt($ch, CURLOPT_HEADER, $header); 
curl_setopt($ch, CURLOPT_POST, $fields); 
curl_setopt($ch, CURLOPT_, $value); 
$response=curl_exec($ch); 
curl_close($ch); 

如果您想進一步的數據,請發表評論我會詳細說明。

+0

請顯示請求標題。 – DanFromGermany

+0

你能告訴我們實際的代碼嗎? – Kita

+0

檢查https。 – Imat

回答

0

此HTTP錯誤通常發生在Web服務器無法理解其收到的請求的部分時。 Internet Explorer可能會將此報告爲「無法找到網頁」.Microsoft Windows爲HTTP 400錯誤 您可以做兩件事: 1: a:清除DNS緩存: b:打開命令提示符:鍵入ipconfig/flushdns c:重新啓動您的網絡瀏覽器。 2:嘗試檢查對象的存檔副本,例如通過在Internet Archive Wayback Machine中輸入地址。

2

400響應表示請求去的HTTP服務器表示請求無效。

爲什麼?

誰知道!也許你在請求中發送的URL有錯誤的參數(在查詢字符串中),或者它可能需要你沒有提供的參數。或者,也許問題是其他標題。

或者它可能只是不喜歡你。

我建議您將發送的請求與網站的API文檔或(真實)瀏覽器發送的請求進行比較。如果失敗,請詢問負責發送請求的Web服務器的人員。