Angular5创建自定义标头

时间:2018-01-12 16:08:49

标签: javascript angular http post http-headers

我有这段代码(简化),我尝试使用http.post发送自定义标题“foo-custom”,但浏览器中的请求是作为200 OPTIONS发送的。到底是什么?

导入

import { Http, Headers, Response, RequestOptions } from '@angular/http'; 

应用

const myheaders = new Headers();
myheaders.append('Content-Type', 'application/json');
myheaders.append('foo-custom', 'var');

const options = new RequestOptions({headers: myheaders});

this.http.post(
  this._url+'search', {}, options
).subscribe(data => {
  console.log("CORRECT!");
  console.log(data);
}, error => {
  console.log("ERROR!");
  console.log(error);    
});

这样做的正确方法是什么?

由于

1 个答案:

答案 0 :(得分:0)

看起来像预检请求,您可以查看this comment

可能duplicated thread

相关问题