我正在尝试等待发帖请求。我找到了 request-promise-native
包来发出等待请求。它适用于 GET 请求,但不适用于 POST。 URL 有效,身份验证哈希有效,并且我已经使用“curl”对其进行了测试。
import * as request from "request-promise-native";
async sendRequest(uri: string, method: string): Promise<any> {
var options = {
uri: uri,
headers: {
"Authorization": 'Basic ' + 'someValidHashValue'
},
method: method,
json: true
};
try {
const result = await request.get(options);
return result;
}
catch (err) {
console.log(err);
}
}
async queueBambooPlan(fileName: string) {
let bambooHost: string | undefined = vscode.workspace.getConfiguration('markdown-table-of-contents').get('atlassianBambooHost');
let planKey = await this.getBambooPlanKey(fileName, bambooHost);
let uri = `${bambooHost}/rest/api/latest/queue/${planKey}`;
let response = await this.sendRequest(uri, 'post');
}
405 - "Apache Tomcat/8.0.36 - Error reportH1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}
HTTP Status 405 - Method Not Allowed
type Status report
message Method Not Allowed
description The specified HTTP method is not allowed for the requested resource.
Apache Tomcat/8.0.36
上面的请求使用fiddler
工作,但是它在代码中不起作用。
更新:我已经使用标准请求包编写了代码并且它正在工作:
最佳答案
您正在使用 request.get
,请改用 request.post
,或者仅使用 request(options)
并设置 method
属性。
关于javascript - 无法发送异步 POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56243090/