[英]Get json with headers by using nodejs
How can I get objects from JSON with headers and send an HTTP get a request to a link?如何从带有标头的 JSON 获取对象并向链接发送 HTTP 获取请求?
setHeader('header1', 'header1_value') for http://getsomejson.com/json.php
and retrieve data then send them to setHeader('header1', 'header1_value') for http://getsomejson.com/json.php
并检索数据然后将它们发送到
randomlinktosenddata.com
You could use a library like request你可以使用像请求这样的库
try this code:试试这个代码:
var request = require('request');
var options = {
url: 'http://getsomejson.com/json.php ',
headers: {
'Some-header': 'header-value'
}
};
request(options, (error, response, body) => {
if (!error && response.statusCode == 200) {
var data = JSON.parse(body);
// use data
request({url:'randomlinktosenddata.com'} , (error,response,body) => {
// do more stuff...
});
}
});
you can install the request library by doing npm install request
您可以通过执行npm install request
来安装请求库
Check this link: https://github.com/request/request检查此链接: https : //github.com/request/request
hope this helps希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.