Texan78 Posted August 12, 2017 Share Posted August 12, 2017 Forgive me if this is simple. My research has brought me to a halt at the moment. I am trying to use cURL to get the response of an API in XML. This is the URL of the API: https://api.weather.gov/alerts/active/region/land By default it returns in JSON. Which I know, I should just use the JSON response but, there is a reason I need it in XML as it will seamlessly integrate into my current code until I can rewrite it for JSON. This is the documentation for the API. Under the API Reference tab is states I just need to change the request header to application/cap+xml. But I am not getting anything back. Just a blank white page. https://alerts-v2.weather.gov/documentation Here is my current code I am using to call the API but I get no response or anything. What am I missing? <?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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/304594-using-curl-to-return-api-xml-response/ Share on other sites More sharing options...
Jacques1 Posted August 12, 2017 Share Posted August 12, 2017 RTFM [To everybody else: The OP is a known troll. Think twice before you invest any time.] Quote Link to comment https://forums.phpfreaks.com/topic/304594-using-curl-to-return-api-xml-response/#findComment-1549719 Share on other sites More sharing options...
Texan78 Posted August 12, 2017 Author Share Posted August 12, 2017 Manual shows nothing about the missing echo statement which is what it was. Also the data I was trying to get a response wasn't available in cap+xml only in atom+xml and JSON. So I will be re-writing the scripts to use JSON which is better now that JSON is available now. Quote Link to comment https://forums.phpfreaks.com/topic/304594-using-curl-to-return-api-xml-response/#findComment-1549720 Share on other sites More sharing options...
Jacques1 Posted August 12, 2017 Share Posted August 12, 2017 Manual shows nothing about the missing echo statement which is what it was. Then you truly cannot read. Quote Link to comment https://forums.phpfreaks.com/topic/304594-using-curl-to-return-api-xml-response/#findComment-1549721 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.