POST数据返回之后多了Content-Type: Content-Length:Access-Control-Allow-Methods:报错
[code=php]<?php
$host = "http://rlsbbd.market.alicloudapi.com";
$path = "/face/verify";
$method = "POST";
$appcode = "d5e971cd87bb4b5c9ae7b9731ef9b0e8";
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
//根据API的要求,定义相对应的Content-Type
array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
$querys = "";
$url = $host . $path;
$bodys['type'] = 0;
$bodys['image_url_1'] = "http://phpcms.web.xinet.com.cn/uploadfile/avatar/20180909526-04.jpg";
$bodys['image_url_2'] = "http://phpcms.web.xinet.com.cn/uploadfile/avatar/20180909525-47.jpg";
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
if (1 == strpos("$".$host, "https://"))
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($bodys));
var_dump(curl_exec($curl));
?> [/code]
http://phpcms.web.xinet.com.cn/123.php
string(952) "HTTP/1.1 200 OK Server: Tengine Date: Sun, 09 Sep 2018 10:04:39 GMT Content-Type: application/json;charset=UTF-8 Content-Length: 175 Connection: keep-alive Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET,POST,PUT,DELETE,HEAD,OPTIONS,PATCH Access-Control-Allow-Headers: X-Requested-With,X-Sequence,X-Ca-Key,X-Ca-Secret,X-Ca-Version,X-Ca-Timestamp,X-Ca-Nonce,X-Ca-API-Key,X-Ca-Stage,X-Ca-Client-DeviceId,X-Ca-Client-AppId,X-Ca-Signature,X-Ca-Signature-Headers,X-Ca-Signature-Method,X-Forwarded-For,X-Ca-Date,X-Ca-Request-Mode,Authorization,Content-Type,Accept,Accept-Ranges,Cache-Control,Range,Content-MD5 Access-Control-Max-Age: 172800 X-Ca-Request-Id: C67AAD52-158E-4E13-8F9C-A34AFFC22714 x-header-requestId: eff16b33-5323-447a-99b1-86a387451a08 {"confidence":87.4157485961914,"thresholds":[61.0,69.0,75.0],"rectA":[172,253,177,253],"rectB":[116,197,192,278],"errno":0,"request_id":"C67AAD52-158E-4E13-8F9C-A34AFFC22714"}"
我只是要:{"confidence":87.4157485961914,"thresholds":[61.0,69.0,75.0],"rectA":[172,253,177,253],"rectB":[116,197,192,278],"errno":0,"request_id":"C67AAD52-158E-4E13-8F9C-A34AFFC22714"}"
curl_setopt($curl, CURLOPT_HEADER, true); 你的这个设置就是要返回响应头的意思,把这里设置为false 请求后返回的就是你想要的了
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。