简体   繁体   English

错误400使用PHP CURL时出现错误请求

[英]Error 400 Bad request when I use PHP CURL

When I CURL in PHP. 当我在PHP中使用CURL With appropriate headers and fields but It will give me error Error 400 Bad request. 使用适当的标题和字段,但它会给我错误错误400错误的请求。 Why this error becomes? 为什么会出现此错误?

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 Request 标头请求

$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";

CURL Code CURL代码

$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);

If you want any further data please comment I will explain in detail. 如果您想要任何进一步的数据,请发表评论我将详细解释。

A 400 response means that the HTTP server that the request went to has said that the request is invalid. 400响应意味着请求进入的HTTP服务器表示请求无效。

Why? 为什么?

Who knows! 谁知道! Maybe the URL you sent in the request has malformed arguments (in the query string) or maybe it requires arguments that you didn't supply. 也许您在请求中发送的URL具有格式错误的参数(在查询字符串中),或者它可能需要您未提供的参数。 Or maybe the problem is the other headers. 或者问题可能是其他标题。

Or maybe it just doesn't like you. 或者它可能只是不喜欢你。

I suggest that you compare the request you are sending with either the web site's API documentation or a request sent by a (real) browser. 我建议您将发送的请求与网站的API文档或(真实)浏览器发送的请求进行比较。 And if that fails, ask the folks who look after the web server you are sending the requests to. 如果失败,请询问那些照顾您发送请求的Web服务器的人。

This HTTP error usually occurs when the web server cannot understand part of a request that it received. 当Web服务器无法理解它收到的请求的一部分时,通常会发生此HTTP错误。 Internet Explorer may report this as “The webpage cannot be found”.Microsoft Windows as HTTP 400 errors Two things that you can do are: 1: a:Clear your DNS cache by : b:opening a Command Prompt:Type ipconfig /flushdns c:Restart your web browser. Internet Explorer可能会将此报告为“无法找到网页”.Microsoft Windows作为HTTP 400错误您可以做的两件事情:1:a:清除DNS缓存:b:打开命令提示符:键入ipconfig / flushdns c :重新启动Web浏览器。 2:Try checking for an archived copy of the object, eg by entering the address in the Internet Archive Wayback Machine. 2:尝试检查对象的存档副本,例如通过在Internet Archive Wayback Machine中输入地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM