无法发送异步发布请求

时间:2019-05-21 16:55:22

标签: javascript node.js typescript async-await

我正在尝试等待发布请求。我发现有request-promise-native包可以发出等待请求。它适用于GET请求,但不适用于POST。该网址正常工作,身份验证哈希也正常工作,以及我已经使用“ 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;颜色:白色;背景颜色:#525D76;字体大小:22px;}   H2   {font-family:Tahoma,Arial,sans-serif;颜色:白色;背景颜色:#525D76;字体大小:16像素;}   H3   {font-family:Tahoma,Arial,sans-serif;颜色:白色;背景颜色:#525D76;字体大小:14px;}   身体   {font-family:Tahoma,Arial,sans-serif;颜色:黑色;背景颜色:白色;}   乙   {font-family:Tahoma,Arial,sans-serif;颜色:白色;背景颜色:#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;   背景颜色:#525D76;边框:无;}   

HTTP状态405-不允许的方法

类型状态报告

消息   不允许的方法

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

Apache Tomcat / 8.0.36

上面的请求使用fiddler起作用,但是不能从代码中起作用。

enter image description here

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

enter image description here

1 个答案:

答案 0 :(得分:3)

您正在使用request.get,而是使用request.post或仅将request(options)method属性集一起使用。

相关问题