【发布时间】:2017-08-12 19:17:52
【问题描述】:
如果这很简单,请原谅我。我的研究让我暂时停了下来。我正在尝试使用 cURL 来获取 XML 中 API 的响应。
这是 API 的 URL:https://api.weather.gov/alerts/active/region/land
默认情况下它以 JSON 格式返回。我知道,我应该只使用 JSON 响应,但是,我需要它在 XML 中是有原因的,因为它将无缝集成到我当前的代码中,直到我可以将它重写为 JSON。
这是 API 的文档。在 API Reference 选项卡下是状态,我只需要将请求标头更改为 application/cap+xml。但我没有得到任何回报。只是一张空白的白页。
https://alerts-v2.weather.gov/documentation
这是我当前用来调用 API 的代码,但我没有得到任何响应或任何东西。我错过了什么?
<?php
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-Type: application/cap+xml;charset=utf-8';
$headers[] = 'Accept: application/cap+xml';
$userAgent = 'php';
$url = 'https://api.weather.gov/alerts/active/region/land';
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HTTPHEADER, $headers);
curl_setopt($cURL, CURLOPT_USERAGENT, $userAgent);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURL, CURLOPT_HTTPGET, true);
$result = curl_exec($cURL);
curl_close($cURL);
?>
【问题讨论】: