Http的帖子来自Fiddler,但不是来自Angular localhost。虽然Http GET确实有用

时间:2017-10-23 17:34:12

标签: angular http asp.net-web-api cors angular-http

此消息由firefox生成。

阻止跨源请求:同源策略禁止在http://localhost:56647/api/Events读取远程资源。 (原因:CORS预检频道没有成功)。

    <httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Allow-Headers" value="Content-Type" />
    <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
  </customHeader>

ANGULAR SERVICE

addEvent(event:Event): Observable<Event> {
let headers = new Headers({'Content-Type':'application/son'});
return this.http.post('http://localhost:56647/api/Events', 
JSON.stringify(event), { headers: headers })
    .map((res: Response) => res.json());
 }

POST CALL

  addEvent( title : string ,postcode : string ,description :  string){
   this.newEvent =  new Eventos(title, postcode, description, postcode, 
    description);
    console.log(this.newEvent);
    this.eventService.addEvent(this.newEvent).subscribe((newEvent) =>{
  this.newEvent = newEvent;
},
(error) => {
  this.statusMessage = 'Problem with the service';
  console.log(error);
});

我已经在web app配置文件中启用了全局以下代码。然而,当做post post时,帖子没有到达web api应用程序。 谢谢

0 个答案:

没有答案