Request used in send request to other domain.
https://blog.csdn.net/wuqingdeqing/article/details/99061026
https://blog.csdn.net/miss1128726/article/details/49976855
a basic sample of request:
1 | var options = { |
This method has limitation for case that expecting to send datas to more than one server. Like, I want to send xml sais to multiple bdc servers, it turns out to only transfer datas to the last bdc. (using request(options, responseHandler
)
A better way to resolve this problem is utilizing request-promise
.
see official API description.
Here is my implementation:
1 | const rp = require('request-promise'); |
0717 UPDATE
ERROR implement request-promise above, note that it returns different paras from original request
Point:
- resolveWithFullResponse: true,
- then(reponse)
Corrected:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20static async sampleFunc(para1, para2, para3) {
var opts = {
url: url,
method: 'GET',
resolveWithFullResponse: true,
auth:{
user: username,
pass: password,
sendImmediately: false
}
};
...
const responseHandler = (res) => {
// the res is a full response containing res.statusCode & res.body
// sample
}
await rp(opts).then(responseHandler).catch((err) => {
// print error in log
});
}