角度4到角度5升级http.post失败

时间:2018-11-16 23:17:13

标签: angular angular-httpclient

我进行了更改,以在新的angular 5中使用httpclient,但是发布失败 并且出现错误,不确定我是否在这里丢失了东西

这是代码

 import { HttpClient, HttpHeaders } from '@angular/common/http';


 const httpOptions = {
    headers: new HttpHeaders({ 'Content-Type': 'application/json; charset=UTF-8' })
 };

 post(inURL, data, config = undefined ) {
    let headers, options;
    if (config){
        options = config;
    } else {
        options = httpOptions;
    }

    let action = this.httpService.post(inURL, data, options);
    return new Promise((resolve, reject) => {
        action.subscribe(
            response => resolve(response),
            error => {
                this.interceptError(error);
                reject(error);
            }
        );
    });

}

正在使用此

在另一个地方调用它
  let xurl = Utilities.vlsiURLWithHost() + 'xxx/setlogintype';
    let xParams = {
        "type": 'xyz'
    }
    // this is not a blocking call
   this.httpService.post(xurl, JSON.stringify(xParams));

在浏览器上的错误如下

  HttpErrorResponse {headers: HttpHeaders, status: 401, statusText: "OK", 
   url: "https://localhost/vlsi/rest/v1/xxx/logintype", ok: false, …}
   error: null
   headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}  message: "Http failure response for 
    https://localhost/vlsi/rest/v1/xxx/logintype: 401 OK"
name: "HttpErrorResponse"

好:错误 状态:401 statusText:“确定”

感谢您的帮助

0 个答案:

没有答案
相关问题