我正在尝试向服务器发送请求,但出现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();
自第一个请求成功以来,我也已附加了网络标头,但第二个没有?!!!
答案 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});
}
我认为您的代码标头添加不正确,请尝试使用此方法添加标头