P
P
Pigeon12352019-09-29 12:50:38
Node.js
Pigeon1235, 2019-09-29 12:50:38

How to solve the error about sending a get request?

An error occurs when sending a request

TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters

Here is the code:
var http = require('http');
        http.get(`http://api.openweathermap.org/data/2.5/weather?q=${city}?lang=ru?units=metric&APPID=My_API_Key`, function(resp){
        var body = ''
        resp.on('data', function(data){
            body += data;
        });

        resp.on('end', function(){
var json = JSON.parse(body);
console.log(body)
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fakeman Cat, 2019-09-29
@Pigeon1235

var http = require('http');
        http.get(`http://api.openweathermap.org/data/2.5/weather?q=${encodeURIComponent(city)}?lang=ru?units=metric&APPID=My_API_Key`, function(resp){
        var body = ''
        resp.on('data', function(data){
            body += data;
        });

        resp.on('end', function(){
var json = JSON.parse(body);
console.log(body)
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question