【问题标题】:get response from GET request to API从 GET 请求获取对 API 的响应
【发布时间】:2016-04-14 10:25:06
【问题描述】:

我正在尝试从 api 调用中获得响应,

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://fm.transfer-to.com/cgi-bin/shop/topup');
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
$response = curl_exec($curl);
echo $response;
$status = curl_getinfo($curl);

curl_close($curl);

//上面的代码什么都不输出

我试过file_get_contents(),但是

$url ="https://fm.transfer-to.com/cgi-bin/shop/topup";
$responses = split("\n", file_get_contents($url));
foreach ($responses as $response) {
    $key = split("=", $response)[0];
    $value= split("=", $response)[1];
    if($key != "" && $value != "") {
        $data[$key] = $value;
    }
}

失败:failed to open stream: Connection timed out.

当我使用表单请求上述 URL 时,如何从 Api 获得响应(API 发回纯文本,而不是 json)。

【问题讨论】:

  • 端点是一个rest api,它需要一些令牌。检查供应商提供的令牌,然后根据文档在请求中使用。

标签: php api curl get response


【解决方案1】:

https 上的这个服务器有only TLSv1 support and very limited and weak ciphers support only,我相信你的 PHP 库没有协商这个配置

解决这个问题

  • 要么让你的 PHP 客户端支持这些服务器支持的东西(不推荐,但只有在此服务器无法更新其配置时才这样做)
  • 仅出于沙盒目的使用 http(不推荐)

【讨论】:

    猜你喜欢
    • 2017-08-22
    • 2016-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-01
    相关资源
    最近更新 更多