我正在尝试调用一个api并发布一个简单的json字符串。当使用VS Code进行调试时,该函数看起来可以工作,但没有返回任何内容。我怀疑我的标题不正确。下面是我的代码:
{return this.http.post(
           url,
           content,
            { headers: this.getCommonHeaders() }
        ).pipe(
            map(response => response.json()),
            tap(data => {
                console.log(data.systemAssignId)
                this.san = data.systemAssignId            
            }),
            catchError(this.handleErrors)
        );}getCommonHeaders函数如下所示:
getCommonHeaders() {
        let headers = new Headers();
        headers.append("Authorization", "Bearer "+ Config.token.toString().trim);
        headers.append("Content-type", "application/json")
        return headers;
    }我已经为此挣扎了好几个小时了。我肯定错过了一些基本的东西,但似乎没有抓住它。该API在Postman中运行良好。
发布于 2019-02-22 01:10:56
你应该使用HttpClient而不是Http模块,因为很久以前它就被弃用了。对于HttpClient,默认的响应格式是JSON。
https://stackoverflow.com/questions/54809688
复制相似问题