我正在使用请求承诺库发出http请求。
但是我遇到以下错误
RequestError:错误:options.uri是必需的参数
public async getClassification(sessionId: any, requestId: any) {
const url = this.config.backendUrl + "/check/classification";
const options = {
method: "GET",
uri: url,
headers: {
"X-IDCHECK-SESSION_ID": sessionId,
"X-IDCHECK-REQUEST_ID": requestId,
},
body: {},
json: true,
simple: false,
resolveWithFullResponse: true,
};
return options;
}
public async retry(name: any, requestOptions: any, data: any, attempts: any): Promise < any > {
console.log("REQ", requestOptions);
let result;
for (let i = 0; i < attempts; i++) {
try {
result = await request(requestOptions);
} catch (err) {
console.log(err);
}
}
return result;
}
您可以在将requetOptions添加到之前查看以下requetOptions的日志 request(RequestOptions);
REQ Promise {
{ method: 'GET',
uri: 'http://localhost:8080/check/classification',
headers:
{ 'X-IDCHECK-SESSION_ID': 5c8d2c15ac84c34fa88bc923,
'X-IDCHECK-REQUEST_ID': 5c8d2c20ac84c34fa88bc926 },
body: {},
json: true,
simple: false,
resolveWithFullResponse: true } }
{
其他解决方案对我不起作用。 1.您在日志中看到的URL带有http。 2.我使用的是uri而不是url。