我有一个使用Angular 2的Ionic2应用程序,它将一个Http PUT发送到ASP.NET Core API服务器。下面是我用来发送请求的方法:
public update(student: Student): Promise<Student>
{
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('authentication', `${student.token}`);
const url = `${this.studentsUrl}`;
return this.http
.put(url, JSON.stringify(student), { headers: headers })
.toPromise()
.then(() => student)
.catch(this.handleError);
}
我在headers对象上设置身份验证密钥/值。
但是当我在服务器上收到这个请求时,我在头上找不到认证密钥:
正如您在图片中看到的,头部上有许多密钥,但没有我在客户端应用程序中手动添加到头部的内容和身份验证密钥。
我做错了什么?
发布于 2016-12-14 10:37:12
http.put()中请求选项的参数实际上应该是RequestOptions类型。尝试如下所示:
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('authentication', `${student.token}`);
let options = new RequestOptions({ headers: headers });
return this.http
.put(url, JSON.stringify(student), options)
发布于 2018-05-29 16:39:53
对于我们来说,我们使用了这样的解决方案:
this.http.get(this.urls.order + '&list', {
headers: {
'Cache-Control': 'no-cache',
}
}).subscribe((response) => { ...
参考here
发布于 2017-09-12 05:27:04
这可以通过从Angular导入headers来轻松解决:
import { Http, Headers } from "@angular/http";
https://stackoverflow.com/questions/41133705
复制相似问题