发送' POST'时出错500请求在节点js中使用基本身份验证

时间:2018-03-08 10:12:58

标签: node.js node-modules

我想在POST方法中点击API,在节点js中使用基本身份验证,但收到错误/server/containers/{id}/processes/{pId}/instances

我尝试了几个代码和提示,但无法获得正确的输出。 在这个帖子方法中,我也必须发送一些数据。

response.statusCode: 500

请帮忙。

1 个答案:

答案 0 :(得分:0)

您可以在Angular Services中使用POST方法访问3个参数的api 1)API网址 2)您要传递的数据 3)标头

标头包含您的身份验证令牌,通过此令牌api可以知道用户是否有效。成功登录后获得的身份验证令牌,必须将其存储在localStorage中。

请参考以下代码

callToApiPost(body):Observable<any> {
    let httpOptions = {
        headers: new HttpHeaders({
            'content-type': 'application/json',
            'authorization': 'bearer ' + localStorage.getItem('your_token')
        })
    }

    return this.http.post('https://xxx-xxxx-aa.domian.com:8443/aa/rest/v2/executions/', body, httpOptions).pipe(
        tap((res:any) => {
            console.log('got the result, api call was successfull');
        }),
        catchError(console.log('error while calling api'))
    )
}