首頁 > php教程 > php手册 > HTTP Status 415

HTTP Status 415

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-06-06 20:14:20
原創
1751 人瀏覽過

使用php curl的方式调用对方提供的接口,收到了如下错误提示 HTTP Status 415The server refused this request because the request entity is in a format not supported by the requested resource for the requested method. Curl 的代码片段如下: $ch =

使用php curl的方式调用对方提供的接口,收到了如下错误提示

HTTP Status 415
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.
登入後複製

Curl 的代码片段如下:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_NOBODY, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
$data = curl_exec($ch);
curl_close($ch);
登入後複製

多次检查curl设置已经接口的说明没有发现问题。对方的服务器使用的是Tomcat 7, 一度怀疑是对方web配置有误,后来仔细研究文档,其中提到Response是jason格式文档,而上述curl中没有指定Request Header 信息, 所以尝试加入一个header, 结果问题解决。 代码如下:

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=utf-8"));
登入後複製
相關標籤:
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
telnet發起http get請求回傳回應問題
來自於 1970-01-01 08:00:00
0
0
0
phpstudy apache http server已停止運作
來自於 1970-01-01 08:00:00
0
0
0
objective-c - OC中Http 是不是基於socket的?
來自於 1970-01-01 08:00:00
0
0
0
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板