php - 使用 URL 中的用户名和密码获取天气 API 的 GET 方法不起作用
问题描述
我在 IBM Cloud Docs Weather 中找到了我的用户名和密码。
我有这个代码:
print file_get_contents("https://d40845df-8125-441f-8e7c-e650726ce721:password@twcservice.mybluemix.net/v1/location/30339:4:US/forecast/hourly/48hour.json");
// of course, the password is my password
我网站上的结果是 Unauthorized.Array()
怎么了?
我可以在https://twcservice.mybluemix.net/rest-api/上访问 Weather API ,这里是可点击的天气 API。
它看起来像这样:
当我填写空输入并单击Try it out!我没有得到回应。
在 IBM Cloud Docs Weather 上,我找到了带有 GET url 的用户名和密码。
解决方案
看起来他们毕竟需要一些授权。
curl -X GET --header 'Accept: application/json' 'https://twcservice.mybluemix.net/api/weather/v1/geocode/33.40/-83.42/forecast/hourly/48hour.json'
我已经在 linux 终端中运行了 curl 并且没有得到授权。
当您尝试直接在浏览器中输入 url 时也是如此。
看看这个:http ://www.remkohde.com/2016/11/14/add-serverless-programming-and-data-integration-on-bluemix/
我认为您确实需要一些授权:
curl -X GET "https://<username>:<password>@twcservice.mybluemix.net/api/weather/v1/geocode/33.40/-83.42/forecast/daily/10day.json?units=m&language=en-US"
我认为 api 可能已经过时了,因为即使是在线测试也会返回奇怪的响应代码0。
推荐阅读
- mongodb - 如何聚合 ObjectId 对数组及其相关集合
- rest - 在 REST API 调用中,如果结果为空,我们应该返回什么
- node.js - 如何使用 MERN 堆栈应用程序上传对象数组,其中某些对象包含文件?
- javascript - 仅当变量包含值时才创建包含变量的数组
- jenkins - Plugin : Publisher over ftp 为什么 ftpPublisher 不知道管道环境中定义的全局变量
- reactjs - 在 useEffect 中调用 Redux Action
- jakarta-ee - 即使数据源出现故障,也要确保应用程序部署
- angular - Angular中工厂异步功能完成后如何设置模块加载顺序?
- crystal-reports - 在水晶报表中使用逗号时换行
- spring - 如何解决不支持的请求方法“POST”?