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

HTTP Status 415

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
풀어 주다: 2016-06-06 20:14:20
원래의
1746명이 탐색했습니다.

使用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"));
로그인 후 복사
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿