Angularjs POST方法405问题

时间:2014-12-10 01:20:25

标签: angularjs

在我的示例应用程序GET&如果我使用localhost,POST正在工作,如果我用系统名称替换POST不起作用。我发现以下错误。

IE:SCRIPT7002:XMLHttpRequest:网络错误0x80070005,访问被拒绝。

Chrome:XMLHttpRequest无法加载htp // machinename / services.svc / api / scenarios / add。无效的HTTP状态代码405

消息:

SEC7118: XMLHttpRequest for http://vijayakatta/HelloService/HelloService.svc/PostData required Cross Origin Resource Sharing (CORS).
File: localhost:31284

SEC7119: XMLHttpRequest for http://vijayakatta/HelloService/HelloService.svc/PostData required CORS preflight.
File: localhost:31284

错误:

SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.
File: localhost:31284

Angularjs:

   this.postData = function (param) {
        return $http.post("http://vbr/HelloService/HelloService.svc/PostData", param)
        .success(function (data, status, headers, config) {
            alert("Success: "+param)
        })
                .error(function (data, status, headers, config) {
                    alert("Error: "+status);
                });
    };

的WebAPI:

 [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "/PostData", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    ResponseData PostData(RequestData data);

服务器web.config:

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

0 个答案:

没有答案