首页 > 解决方案 > 使用 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 的用户名和密码。

在此处输入图像描述

标签: phpgetibm-cloudweather-api

解决方案


看起来他们毕竟需要一些授权。

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


推荐阅读