javascript - 将请求正文与 requestjs 一起使用
问题描述
我正在使用requestjs向https://www.handelsregister.de/rp_web/search.do发送请求。
请求应如下所示:
如何添加请求正文?
我的尝试:
function callback(error, response, body) {
if (error) return error;
// write the body to an external file
fs.writeFileSync('body.html', body);
return body;
}
function writeFile(url = 'https://www.handelsregister.de/rp_web/search.do') {
const headers = {
// headers, as you can see in the picture. I am sure my headers a correct.
// this is probably NOT the right place for using a request body, right? At least it does not work ...
qs:
'suchTyp=n®isterArt=®isterNummer=®istergericht=R3102&schlagwoerter=&schlagwortOptionen=2&ergebnisseProSeite=100&btnSuche=Find'
};
const options = {
url, // https://www.handelsregister.de/rp_web/search.do
headers
};
return request(options, callback);
}
writeFile().then(() => {
console.log('finished');
});
解决方案
尝试这样的事情。
data= {
key1:value1,
key2:value2,
...
...
}
request.post({url:' https://www.handelsregister.de/rp_web/search.do',form: data},
function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error('request failed:', err);
}
console.log('Request successful! Server responded with:', body);
);
推荐阅读
- r - 在 R 中映射南极洲
- c - 为什么 Visual Studio Code 无法编译我的 C 代码?
- node.js - 我想返回帖子数组,但我得到了一个空数组
- javascript - JavaScript 代理:简单的日志函数,将字符串参数代理到 console.log()
- firebase - getter 'uid' 在颤振中被调用为 null
- python - Python 元音常量
- python-3.x - FileNotFoundError Traceback(最近一次调用最后一次)
- regex - 正则表达式匹配具有不同值的字符串
- html - div 中两个 hr 标签之间的表格。表格不会从 div 中获取所有属性
- pygame - 如何让子弹从玩家点向光标移动?