开发者社区> 问答> 正文

Content-Length:Access-Control-Allow-Methods:报错

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"}"

展开
收起
kun坤 2020-06-14 09:57:58 709 0
1 条回答
写回答
取消 提交回答
  • curl_setopt($curl, CURLOPT_HEADER, true); 你的这个设置就是要返回响应头的意思,把这里设置为false 请求后返回的就是你想要的了

    2020-06-14 09:58:03
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
AutoAlerts-From Data to Action 立即下载
Cloak-And-Dagger-From-Two-Permissions-To-Complete-Control-Of-The-UI-Feedback-Loop 立即下载
低代码开发师(初级)实战教程 立即下载