2016-11-04 7 views
0

AzureのAPI管理の最上位スコープで、次のCORSポリシーを提供する:AzureのAPI管理 - CORSの問題

<policies> 
     <inbound> 
      <cors> 
       <allowed-origins> 
        <origin>*</origin> 
       </allowed-origins> 
       <allowed-methods> 
        <method>*</method> 
       </allowed-methods> 
       <allowed-headers> 
        <header>*</header> 
       </allowed-headers> 
       <expose-headers> 
        <header>*</header> 
       </expose-headers> 
      </cors> 
     </inbound> 
     <backend> 
      <forward-request /> 
     </backend> 
     <outbound /> 
    </policies> 

使用:

var xhr = new XMLHttpRequest(); 
    xhr.open('GET', 'https://mydomain.azure-api.net/calc/add?a=5&b=5');     
    xhr.send(); 

生の要求:

GET https://mydomain.azure-api.net/calc/add?a=5&b=5 HTTP/1.1 
    Host: mydomain.azure-api.net 
    Connection: keep-alive 
    Origin: https://any.com 
    User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36 
    Accept: */* 
    Referer: https://any.com/ 
    Accept-Encoding: gzip, deflate, sdch, br 
    Accept-Language: en-US,en;q=0.8,de;q=0.6,pl;q=0.4 

エラーメッセージ:

XMLHttpRequest cannot load https://mydomain.azure-api.net/calc/add?a=5&b=5. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://any.com' is therefore not allowed access. The response had HTTP status code 401. 

生の応答:私は成功メッセージを受信して​​い

GET https://mydomain.azure-api.net/calc/add?a=5&b=5 HTTP/1.1 
    Host: mydomain.azure-api.net 
    Connection: keep-alive 
    Origin: https://any.com 
    User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36 
    Ocp-Apim-Subscription-Key: ********************** 
    Accept: */* 
    Referer: https://any.com/ 
    Accept-Encoding: gzip, deflate, sdch, br 
    Accept-Language: en-US,en;q=0.8,de;q=0.6,pl;q=0.4 

var xhr = new XMLHttpRequest(); 
    xhr.open('GET', 'https://mydomain.azure-api.net/calc/add?a=5&b=5');  
    xhr.setRequestHeader('Ocp-Apim-Subscription-Key', '**********************'); 
    xhr.send(); 

生の要求:できるだけ早く私は、正しいAPIキーを使用するよう

HTTP/1.1 401 Access Denied 
    Content-Length: 152 
    Content-Type: application/json 
    WWW-Authenticate: AzureApiManagementKey realm="https://mydomain.azure-api.net/calc",name="Ocp-Apim-Subscription-Key",type="header" 
    Date: Fri, 04 Nov 2016 09:31:15 GMT 

    { "statusCode": 401, "message": "Access denied due to missing subscription key. Make sure to include subscription key when making requests to an API." } 

生の応答:

HTTP/1.1 200 OK 
    Cache-Control: no-cache 
    Pragma: no-cache 
    Content-Length: 123 
    Content-Type: application/xml; charset=utf-8 
    Expires: -1 
    X-AspNet-Version: 4.0.30319 
    X-Powered-By: ASP.NET 
    Access-Control-Allow-Origin: * 
    Access-Control-Expose-Headers: Content-Length,Date,Server,X-AspNet-Version,X-Powered-By 
    Date: Fri, 04 Nov 2016 09:34:44 GMT 

    <result><value>10</value><broughtToYouBy>Azure API Management - http://azure.microsoft.com/apim/ </broughtToYouBy></result> 

質問:

それは正しくない/無APIキーは、AzureのAPI管理から、この予想される動作は、提供されていないときにのみ起こるCORSの問題のように私には見えますか?

答えて

0

簡潔に言えば、表示される正しいエラーメッセージはわかりませんが、API管理ソリューションは通常のAPIと同じようにサブスクリプションIDとキーに基づいているため、必要な情報を渡します。

+0

私はAPIキーがなくても動作するとは思っていませんが、APIキーを使わずにクエリを実行しながら、ブラウザコンソールにCORSメッセージ(IE、Firefox、Chrome、その他のカップルで起こります) .. –