【发布时间】:2014-04-18 04:23:36
【问题描述】:
我有简单的 Angular js 应用程序。我有一个简单的身份验证方法。在 Internet Explorer 中执行该方法时,WCF 方法会接收带有数据的参数。当从 firefox 执行 ame 代码时,服务器上的参数为 null。
$http({
url: Url,
method: "POST",
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
data: AuthenticateRequest
});
WCF 方法
[WebInvoke(RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
Method = "*",
BodyStyle = WebMessageBodyStyle.Bare)]
[OperationContract]
AuthenticateResponse Authenticate(AuthenticateRequest AuthenticateRequest);
Fiddler IE 信息
POST http://www.api.com:56586/V1/Service.svc/json/Authenticate HTTP/1.1
X-Requested-With: XMLHttpRequest
Accept: application/json, text/plain, */*
Content-Type: application/json; charset=utf-8
Referer: http://www.api.com:54567/
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko
Host: localhost:56586
Content-Length: 45
DNT: 1
Connection: Keep-Alive
Pragma: no-cache
{"UserName":"username","Password":"password"}
Firefox Fiddler 信息
OPTIONS http://www.api.com:56586/V1/Service.svc/json/Authenticate HTTP/1.1
Host: www.api.com:56586
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Origin: http://www.api.com:54567
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type,x-requested-with
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
【问题讨论】:
-
FF 发送的是
OPTIONSrequest,而不是POST。因此你没有得到有效载荷。您的 Web 应用程序和 Web 服务是否托管在同一主机/端口上?您是否在浏览器 javascript 控制台中获得任何信息?
标签: c# json wcf angularjs firefox