繁体   English   中英

无法发送异步发布请求

[英]Can't send async post request

我正在尝试等待发布请求。 我发现了request-promise-native软件包可以发出等待请求。 它适用于GET请求,但不适用于POST。 URL有效,auth哈希有效,正如我已经用`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-错误报告H1 {font-family:Tahoma,Arial,sans-serif; color:white; background-color:#525D76; font-size:22px;} H2 {font-family:Tahoma ,Arial,sans-serif;颜色:白色;背景颜色:#525D76;字体大小:16px;} H3 {font-family:Tahoma,Arial,sans-serif;颜色:白色;背景颜色:#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:黑色;}。line {高度:1像素;背景色:#525D76;边框:无;}

HTTP状态405-不允许的方法

类型状态报告

消息不允许的方法

说明所请求的资源不允许使用指定的HTTP方法。

Apache Tomcat / 8.0.36

上面的请求使用fiddler ,但是该请求无法通过代码进行工作。

在此处输入图片说明

更新:我已经使用标准请求包编写了代码,并且可以正常工作:

在此处输入图片说明

您使用request.get ,使用request.post代替或者干脆使用request(options)method属性集。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM