1
我想從API調用響應響應,得到GET請求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.
如何從API獲取響應(API發回原始文本,而不是json),當我使用表單向上面的URL請求時。
終點是一個REST API,並且預計一些令牌。檢查供應商提供的令牌,然後根據文檔在請求中使用。 – vishwakarma09