AngularJS的http.get方法返回404错误

5
我正在尝试使用AngularJS从openweathermap.org API获取一个JSON,但我的请求返回了错误代码404。这是我的代码: $scope.key = "XXXXXXXXXXXXX"; $scope.search = "Rouen"; $scope.url= "api.openweathermap.org/data/2.5/weather?q=" + $scope.search + "&APPID=" + $scope.key; $scope.fetch = function(){ $http.get($scope.url) .then(function(response){ $scope.res = response.data; $scope.status= response.status;}, function errorCallback(response) { alert(response.status);}); }
我已经尝试请求另一个URL,并且得到了与此相同的问题:http://www.omdbapi.com/?t=Sherlock%20Holmes&tomatoes=true&plot=full 有人知道这里出了什么问题吗?
如果有任何帮助,请谅解,我刚刚开始学习AngularJS,我在其他主题上没有找到任何解决方案。
谢谢您提前的答复!

“//”在哪里? - epascarello
这是错误,缺少http://,愚蠢的^^谢谢。 - V. Déhaye
1个回答

2
我看到的唯一错误是您没有在URL前设置http://。
这是我在Chrome上看到的响应。
Request URL:http://api.openweathermap.org/data/2.5/weather?q=Rouen&APPID=XXXXXXXXXXXXX
Request Method:GET
Status Code:401 Unauthorized
Remote Address:192.241.169.168:80

当然,如果APPID无效,则会返回401未经授权的状态码。


干得好,那是我的错误,现在它可以工作了,我真是个白痴!非常感谢你。 - V. Déhaye

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接