安装
--
使用
var request = require('request');
var url = 'https://www.sojson.com/open/api/weather/json.shtml?city=北京';
request(url, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
});
var url = 'https://www.sojson.com/open/api/weather/json.shtml';
var requestData = {
city: '北京'
};
request({
url: url,
method: 'post',
json: true,
headers: {
'content-type': 'application/json',
},
body: JSON.stringify(requestData)
}, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
});
var url = 'https://www.sojson.com/open/api/weather/json.shtml';
request.post({
url: url,
form: {
city: '北京'
}
}, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
});