2016-03-22 3 views
0

基本認証を使用してBigCommerce API(https://developer.bigcommerce.com/api)にAPI呼び出しを行いたいと思います。CORSのためBigCommerce APIに認証できません

私のAJAX呼び出しは、次のようになります。

$.ajax({ 
    type: 'GET', 
    url: 'https://store-zkk8z5i.mybigcommerce.com/api/v2/products', 
    xhrFields: { 
     withCredentials: true 
    }, 
    headers: { 
     'Authorization': 'Basic ' + MY_TOKEN, 
     'Accept': 'application/json' 
    }, 
    success: function (event) { 
     debugger 
    }, 
    error: function (error) { 
     debugger 
    } 
}); 

をしかし、私は次のエラー得続ける:

XMLHttpRequest cannot load https://store-zkk8z5i.mybigcommerce.com/api/v2/products . Response to preflight request doesn't pass access control check: A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin ' http://store-zkk8z5i.mybigcommerce.com ' is therefore not allowed access. The credentials mode of an XMLHttpRequest is controlled by the withCredentials attribute.

は私が成功した応答を得るために、私の資格情報が大丈夫であることを確信しているの際にI私の要求をcURLで行います。

アイデア?

答えて

1

I'm pretty sure that my credentials are okay

これは、むしろその要点です。エラーメッセージを見てください:

A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true.

あなたが資格情報を送信しているので、あなたはAccess-Control-Allow-Originにワイルドカードを使用することはできません。

あなたはAccess-Control-Allow-Origin: http://store-zkk8z5i.mybigcommerce.comで、Access-Control-Allow-Origin: *ではありません。

+0

これを追加するには、セキュリティ上の理由から店頭から直接APIにリクエストすることをおすすめしません。 https://stackoverflow.com/questions/35942220/is-bigcommerce-api-supports-cors – Alyss

+0

Access Control-Allow-Originヘッダーを*に設定することは決してありません。私はブラウザがそれを単独でやっていると思う。それを止める方法はありますか?私はあなたが示唆した方法でそれを設定しようとしました。違いはありません。 – satnam

+0

ブラウザはそれをやっていない、 'store-zkk8z5i.mybigcommerce.com'です。これはHTTP応答ヘッダーです。 'store-zkk8z5i.mybigcommerce.com'を管理していない場合は、(a)誰に変更を依頼するか、(b)withCredentialsを設定しないでAPIを使用する方法を説明するドキュメントを見つける必要があります: true '...しかし、Alyssのコメントではどちらもそうは思われないので、おそらくサーバーからのHTTPリクエストの作成に切り替えるべきです。 – Quentin

関連する問題