从angularjs GET调用WCF,POST不行

时间:2014-09-11 10:08:39

标签: angularjs wcf rest

我正在从我的angularjs-application(同一台机器)调用iis托管的wcf服务。在一个函数上做一个GET调用我得到了结果,但是在POST时,调用没有通过。相反,我得到401.2未经授权。我正在使用HTTPS并且在IIS中启用了Windows身份验证并且禁用了匿名

使用高级Rest客户端(chrome插件)时,调用有效。

Fiddler显示以下标题: 要求:

https://bechtlehrservice.sharepoint.hansevis13a.dev.hansevision.de/HrService.svc/rest/SetDailyDetails HTTP/1.1
Host: bechtlehrservice.sharepoint.hansevis13a.dev.hansevision.de
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: https://localhost:44305
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36
Access-Control-Request-Headers: accept, content-type
Accept: */*
Referer: https://localhost:44305/Pages/PresenceDetail.aspx?SPHostUrl=https%3A%2F%2Fbechtlehr%2Esharepoint%2Ehansevis13a%2Edev%2Ehansevision%2Ede&SPLanguage=en-US&SPClientTag=4&SPProductNumber=15%2E0%2E4505%2E1005
Accept-Encoding: gzip,deflate
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4

响应:

https://bechtlehrservice.sharepoint.hansevis13a.dev.hansevision.de/HrService.svc/rest/SetDailyDetails HTTP/1.1
Host: bechtlehrservice.sharepoint.hansevis13a.dev.hansevision.de
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: https://localhost:44305
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36
Access-Control-Request-Headers: accept, content-type
Accept: */*
Referer: https://localhost:44305/Pages/PresenceDetail.aspx?SPHostUrl=https%3A%2F%2Fbechtlehr%2Esharepoint%2Ehansevis13a%2Edev%2Ehansevision%2Ede&SPLanguage=en-US&SPClientTag=4&SPProductNumber=15%2E0%2E4505%2E1005
Accept-Encoding: gzip,deflate
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4

我的Wcf配置:

  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="https://localhost:44305" />
    <add name="Access-Control-Allow-Credentials" value="true" />
    <add name="Access-Control-Allow-Headers" value="Authorization, Origin, Content-Type, Accept, X-Requested-With" />
    <add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS" />
    <add name="Access-Control-Max-Age" value="1728000" />
  </customHeaders>

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

这是一个CORS问题。我们通过在IIS中的顶部设置OPTIONS-Handler为wcf服务站点解决了这个问题。