Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
189
rated 0 times [  196] [ 7]  / answers: 1 / hits: 26652  / 6 Years ago, sat, february 24, 2018, 12:00:00

I am trying to sent an HTTP request with Axios, but I get a 404 error. The reason is that the request gets sent with the local host IP at the beginning of the URL, why is this happening?



JS:



function getWeather() {

axios.get('api.openweathermap.org/data/2.5/weather', {
params: {
lat: 30.18,
lon: 30.87,
appid: '57d9478bc08bc211f405f45b93b79272'
}
})
.then(function(response) {
console.log(response);
})

.catch(function(error) {
console.log(error);
})
};
getWeather();


ERROR:



http://127.0.0.1:5500/api.openweathermap.org/data/2.5/weather?lat=30.18&lon=30.87&appid=57d9478b#####################3b79272 404 (Not Found)

More From » http

 Answers
17

In the URL argument for Axios, you are not specifying the protocol to use for your API request (probably HTTP). Because of that, Axios interprets it as a relative URL path and adds the path of your local server, because it needs a full URL to make the request.



You can easily fix it by adding the http:// prefix:



axios.get('http://api.openweathermap.org/data/2.5/weather', {

[#55076] Tuesday, February 20, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bryonk

Total Points: 161
Total Questions: 116
Total Answers: 107

Location: Albania
Member since Sun, Nov 22, 2020
4 Years ago
bryonk questions
;