在Ionic中将Http请求返回401错误

时间:2018-10-07 09:49:34

标签: api ionic-framework put

我正在尝试向服务器发送请求,但出现401错误

提供者

putData(){
header = header.append('Content-Type', 'application/json');
        header = header.append('Accept', 'application/json');
        header = header.append('Authorization', 'Bearer');

      return this.http.put('http://something//', {headers: header})
          .subscribe((result: any) => {
               console.log(result);
          }, (errorResponse) => {
              console.error(errorResponse);

}

home.ts

this.MyProvider.putData();

自第一个请求成功以来,我也已附加了网络标头,但第二个没有?!!!

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

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

  constructor(public http: HttpClient )
putData(){

 const headers = new HttpHeaders({'Authorization':'Basic'});
     return this.http.post("'http://something//'", {headers: headers});
}

我认为您的代码标头添加不正确,请尝试使用此方法添加标头