简体   繁体   English

无法发送异步发布请求

[英]Can't send async post request

I'm trying to await post request. 我正在尝试等待发布请求。 I've found request-promise-native package to make await requests. 我发现了request-promise-native软件包可以发出等待请求。 It works for GET requests but doesn't work with the POST. 它适用于GET请求,但不适用于POST。 The URL is working, the auth hash is working as well as I've tested it with `curl. 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 - 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;} 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 Status 405 - Method Not Allowed HTTP状态405-不允许的方法

type Status report 类型状态报告

message Method Not Allowed 消息不允许的方法

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

Apache Tomcat/8.0.36 Apache Tomcat / 8.0.36

The request from above worked using fiddler , however it is not working from the code. 上面的请求使用fiddler ,但是该请求无法通过代码进行工作。

在此处输入图片说明

UPDATE: I've wrote the code using standard request package and it is working: 更新:我已经使用标准请求包编写了代码,并且可以正常工作:

在此处输入图片说明

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

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

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