发送 JSON 参数
var request = require('request');
var options = {
uri: 'https://www.googleapis.com/urlshortener/v1/url',
method: 'POST',
json: { "longUrl": "http://www.google.com/" }
};
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body.id) // Print the shortened url.
}
});
GET 方法
request.get(url, function(error, response, body) {
console.log(JSON.parse(body));
});
网友评论