Tag: http options method

Access-Control-Allow-Origin标头不起作用 – 我做错了什么?

我试图提供HTTP OPTIONS方法的响应,Access-Control-Allow-Origin标头复制请求中Origin标头的内容。 由于我无法弄清楚的原因,这显然不起作用。 tl; dr:来自OPTIONS的回应说: Access-Control-Allow-Origin: http://10.0.0.105:9294 随后的GET有: Origin:http://10.0.0.105:9294 Chrome说: Origin http://10.0.0.105:9294 is not allowed by Access-Control-Allow-Origin WTF不是吗? 更多详情… 通过查看Chrome的开发人员工具窗口,请求标头是: OPTIONS /user/kris HTTP/1.1 Host: 10.0.0.104:8080 Connection: keep-alive Access-Control-Request-Method: GET Origin: http://10.0.0.105:9294 User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.75 Safari/537.1 Access-Control-Request-Headers: origin, x-requested-with, content-type, accept Accept: */* Referer: http://10.0.0.105:9294/ Accept-Encoding: gzip,deflate,sdch Accept-Language: en-GB,en-US;q=0.8,en;q=0.6 […]

将JSON数据从JQuery发送到WCF REST方法时出现问题

我在使用jquery将一些json数据发布到我在WCF服务上的rest方法时遇到了一些麻烦。 在WCF方面,这是操作合同: [OperationContract] [WebInvoke(Method = “POST”, BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = “PostSomething”)] MyResult PostSomething(MyRequest request); MyResult和MyRequest都标有所有必需的DataContract和DataMember属性,服务正在暴露WebHttp端点。 在JQuery方面,这是我的函数调用: var jsonStr = JSON.stringify(reqObj); $.ajax({ type: “POST”, dataType: “json”, url: “http://localhost/MyService/PostSomething”, contentType: “application/json; charset=utf-8”, data: jsonStr, success: function (html) { alert(html); } }); 这个请求永远不会到达我的方法(我每次都得到一个405方法不允许),并查看Charles的请求如下所示: OPTIONS /MyService/PostSomething HTTP/1.1 Host: localhost Cache-Control: max-age=0 Access-Control-Request-Method: […]