简体   繁体   中英

AngularJS http.get returns 404

I am trying to get a JSON from the openweathermap.org API using AngularJS, but my request returns an error code 404. Here is my code :

$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);});

I have tried requesting another url, and got the same problem with this one : http://www.omdbapi.com/?t=Sherlock%20Holmes&tomatoes=true&plot=full

Does someone have an idea about what is wrong here ?

Forgive me if that is obvious, I am brand new in AngularJS and I haven't found any solution on other topics.

Thank you in advance for your answers !

The only error I see is that you are not setting http:// before the url

this is the response on my 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

of course a 401 Unauthorized for the APPID not being valid

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM