【发布时间】: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,它需要一些令牌。检查供应商提供的令牌,然后根据文档在请求中使用。