简体   繁体   中英

Can't send async post request

I'm trying to await post request. I've found request-promise-native package to make await requests. It works for GET requests but doesn't work with the POST. The URL is working, the auth hash is working as well as I've tested it with `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

Status report 状态报告

Method Not Allowed 不允许的方法

The specified HTTP method is not allowed for the requested resource. 所请求的资源不允许使用指定的HTTP方法。

Apache Tomcat/8.0.36

The request from above worked using fiddler , however it is not working from the code.

在此处输入图片说明

UPDATE: I've wrote the code using standard request package and it is working:

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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