为什么 wcf web 服务通过 ssl 托管在 iis 中。结果是“403禁止”? Jquery $.post 发送 OPTIONS 动词?
我有一个托管在 IIS 中的 WCF Web 服务。它使用 webHttpBinding。方法上有 WebInvoke 属性,以便可以以 REST 方式访问它们。我可以像这样成功地使用它们: http://mydomain.com/MyService.svc/some/rest/style/东西 并将参数 POST 到 Web 服务。
现在我想通过非标准端口 7777 将其更改为 HTTPS。我正确配置了 IIS,获得了证书和所有内容。我可以通过 https://mydomain.com:7777 访问 html 页面。 我添加了修改后的 webhttpbinding 以添加安全节点,如下所示:
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
</security>
我还更改了我的行为的 servicemetadata 节点并删除了 httpGetEnabled='true' 并添加了 httpsGetEnabled='true'
我可以访问 https://mydomain.com:7777/MyService.svc 并获取信息屏幕。
我可以访问 https://mydomain.com:7777/MyService.svc /some/rest/style/thing 使用http get,我收到一条“方法不允许”消息。
但是如果我尝试访问 https://mydomain.com:7777/ MyService.svc/some/rest/style/thing 带有 POST 我收到 403 禁止
更新一些更多信息
我正在缩小问题范围
我正在使用 jQuery 并通过 $.post("< a href="http://mydomain.com/" rel="nofollow noreferrer">http://mydomain.com/....."。“数据”,回调,“json”)。 .那有效 现在我正在做 $.post("https://mydomain.com:7777/.... ."."data",callback,"json")..这给了我一个 403...使用 firebug 我看到它不是发送 POST,而是最初发送 OPTIONS..这就是给 403 的
原因可能是jquery的问题
I have a WCF Webservice hosted in IIS. It uses a webHttpBinding. There are WebInvoke attributes on the methods so that they can be access REST style. I can successfully use them like so:
http://mydomain.com/MyService.svc/some/rest/style/thing
and POST to that the arguments to the web service.
Now I want to change this to HTTPS over a nonstandard port 7777. I configured IIS correctly, got the cert and everything. I can access html pages over https://mydomain.com:7777.
I added a modified the webhttpbinding to add a security node like so:
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
</security>
I also changed my behavior's servicemetadata node and removed httpGetEnabled='true' and added httpsGetEnabled='true'
I can access https://mydomain.com:7777/MyService.svc and get a screen of info.
I can access https://mydomain.com:7777/MyService.svc/some/rest/style/thing using http get and i get a "Method not allowed" message.
BUT If I try to access https://mydomain.com:7777/MyService.svc/some/rest/style/thing with a POST I get a 403 forbidden
update some more info
I'm narrowing down the problem
I am using jQuery and accessing the webservice via a $.post("http://mydomain.com/.....". "data", callback, "json")..that worked
now I am doing $.post("https://mydomain.com:7777/.....". "data", callback, "json")..and that gives me a 403...using firebug I see instead of sending a POST, it is sending OPTIONS initially..and that is what is giving the 403
this might be a jquery problem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
JQuery $.ajax、$.get、$.post 调用不允许跨域调用。当您确实创建一个时,它会发送 OPTIONS 动词而不是 POST 动词,尽管请求方法是 POST。
其他解决方法可能是创建另一个子域,该子域指向您要实际调用的 URL 的 IP 地址。
JQuery $.ajax, $.get, $.post calls dont allow cross-domain calls. When you do make one, it sends OPTIONS verb instead of the POST verb, though the request method is POST.
Other work around could be creating another sub-domain which points to IP address of the URL you want to actually invoke.
您需要运行httpcfg 以使 IIS 侦听非标准端口上的 SSL 流量。
You need to run httpcfg to get IIS to listen for SSL traffic on a non standard port.
Puffpio:
请检查以确保您附加了“callback=?”参数到您的请求 URI。然后您应该在请求标头中看到 GET 动词。
从 jQuery 文档页面:
希望这有帮助,
Michael Ibarra
Puffpio:
Please check to ensure that you're appending the "callback=?" parameter to your request URI. Then you should be seeing the GET verb in your request header.
From the jQuery documentation page:
Hope this helps,
Michael Ibarra
如果您使用 MOZILLA 火狐作为浏览器,那么它会预检请求并使用 OPTIONS 动词发送请求,当服务器返回 200 OK 状态时,它会使用 POST 动词请求实际数据。
跨域问题。
因特卡布
If you are using the MOZILLA fire fox as a browser then it preflight the request and send a request with OPTIONS verb and when server returns the 200 OK status then it request the actual data with the POST verb.
CROSS domain issue.
Intekhab
我发现我遇到了同样的问题,使用 jQuery 的 .load 函数的 Ajax 调用返回 403 错误。我必须进入 IIS 管理器的默认网站属性上的主目录,选择“配置”,然后编辑 .cgi 扩展名的属性,使其包含 OPTION 动词。找到您的问题和随后的评论帮助我快速解决了这个问题。
I found that I had the same problem where Ajax calls using jQuery's .load function were returning 403 errors. I had to go into the Home Directory on the IIS Manager's Default Web Site's properties and select Configuration and then edit the .cgi extension's properties so that it included the OPTION verb. Finding your question and subsequent comment helped me resolve this quickly.