调用REST服务时不允许使用HTTPS 405方法

时间:2016-06-16 14:42:21

标签: javascript rest post https cross-domain

我正试图从Unix服务器上托管的网站上点击Windows Server上托管的HTTPS REST服务,但我收到405 Method Not Allowed错误。

我在浏览器控制台上遇到的异常是::

  

OPTIONS   https://auth.syrasoft.com/10.0.0.101/authservice.svc/rest/r_PerformLogin   XMLHttpRequest无法加载   https://auth.syrasoft.com/10.0.0.101/authservice.svc/rest/r_PerformLogin。   预检的响应具有无效的HTTP状态代码405

尝试访问REST服务的我的客户端代码是:

createCORSRequest: function(method, url) {
            var xhr = new XMLHttpRequest();
            if ("withCredentials" in xhr) {
                // Most browsers.
                xhr.open(method, url, true);
            } else if (typeof XDomainRequest != "undefined") {
                // IE8 & IE9
                xhr = new XDomainRequest();
                xhr.open(method, url);
            } else {
                // CORS not supported.
                xhr = null;
            }
            return xhr;
        },
        doSignIn: function(event) {
            console.log('inside sign in');
            event.preventDefault();
            $('#ErrMsg').hide(); // Hide any errors on a new submit

            console.log('Logging in... ');

            var url = 'https://auth.syrasoft.com/10.0.0.101/authservice.svc/rest/r_PerformLogin';
            var method = 'POST';
            var formValues = {
                AccountID: 28462,
                CurrentVersion: "10.0.0.103",
                GoogleRedirect: null,
                GoogleToken: null,
                GroupID: 0,
                Method: 2,
                PC_Name: "DEV7",
                Password: [97, 136, 201, 199, 60, 1, 89, 216, 184, 191, 82, 1, 114, 252, 127, 16, 0, 184, 64, 9, 82, 84, 81, 147, 12, 83, 100, 38, 197, 209, 252, 151],
                Source: 0,
                UserName: "mikeo"
            };

            var xhr = this.createCORSRequest(method, url);
            xhr.setRequestHeader("Content-Type","application/json");
            xhr.setRequestHeader("X-Requested-With","XMLHttpRequest");
            xhr.setRequestHeader("Accept","application/json");
            xhr.onload = function() {
                console.log('success');
                var data = xhr.responseText;
                if (data) {
                    var json = jQuery.parseJSON(data);
                    console.log(json);
                    app.navigate("home", {
                        trigger: true
                    });
                }
            };
            xhr.onerror = function() {
                console.log('error');
                var data = xhr.responseText;
                if (data) {
                    var json = jQuery.parseJSON(data);
                    $('#ErrMsg').text(json.error.text).show();
                }
            };

            xhr.send(JSON.stringify(formValues));
        }

REST服务器端的配置是:

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="EnableDebugLogging" value="true" />
    <add key="LogFileName" value="AuthenticationService.txt" />
  </appSettings>
  <system.web>
        <customErrors mode="Off"/>
    <compilation strict="false" explicit="true" targetFramework="4.0">
      <assemblies>
        <add assembly="MySql.Data, Version=6.9.5.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D" />
      </assemblies>
    </compilation>
    <pages>
      <namespaces>
        <add namespace="System.Runtime.Serialization" />
        <add namespace="System.ServiceModel" />
        <add namespace="System.ServiceModel.Web" />
      </namespaces>
    </pages>
  </system.web>
  <system.serviceModel>
    <client>
      <endpoint address="http://localhost:64331/AutoUpdate.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IVersionCheck" contract="AutoUpdateService.IVersionCheck" name="BasicHttpBinding_IVersionCheck" />
    </client>
    <services>
      <service name="AuthenticationService">
        <endpoint address="" binding="wsHttpBinding" name="wb" contract="IAuthenticationService" bindingConfiguration="wb">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint name="restful" address="rest" binding="webHttpBinding" contract="IRESTfulAuth" bindingConfiguration="bw" behaviorConfiguration="web"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <!--Binding Settings-->
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IVersionCheck" />
      </basicHttpBinding>
      <wsHttpBinding>
        <binding name="wb" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00">
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </wsHttpBinding>
            <webHttpBinding>
                <binding name="bw" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00">
                    <security mode="Transport">
                        <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
                    </security>
                </binding>
            </webHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="false" />
    <httpProtocol>
     <customHeaders>
       <add name="Access-Control-Allow-Headers" value="Content-Type,Accept,X-Requested-With" />
       <add name="Access-Control-Allow-Origin" value="http://syrasoftconnect.com" />
       <add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS,PUT,DELETE" />
     </customHeaders>
   </httpProtocol>
  </system.webServer>
</configuration>

这里的事情是当我通过SOAP UI模拟REST服务时,我完全能够从网站上调用它,但不能在Windows服务器上托管它。我相信服务器配置可能存在一些问题,但我无法确定它。我已经尝试了几乎所有与stackoverflow相关的解决方案,但是没有运气。

你们看到我的代码或服务器配置有什么问题吗?

0 个答案:

没有答案