1

Hy, Microsoft Cognitive Services API'sini sunucu/yerel makinemden JavaScript ile erişmeye çalıştığımda aşağıdaki hatayı alıyorum.Microsoft Cognitive Services JavaScript 'Erişim-Denetim-İzin-Kökeni' İstek

function requestAPI(){ 
var params = { 
     // Request parameters 
     "visualFeatures": "Categories" 
}; 

$.ajax({ 
     url: "http://api.projectoxford.ai/vision/v1.0/analyze?" + $.param(params), 
     beforeSend: function(xhrObj){ 
      // Request headers 
      xhrObj.setRequestHeader("Content-Type","application/json"); 
      xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","{myKey}"); 
     }, 
     type: "POST", 
     // Request body 
     data: "{'url':'http://www.html5canvastutorials.com/demos/assets/darth-vader.jpg'}", 
    }) 
    .done(function(data) { 
     alert("success"); 
    }) 
    .fail(function() { 
     alert("error"); 
    }); 

} Zaten eklendi Benim .htaccess olarak

:

XMLHttpRequest cannot load http://api.projectoxford.ai/vision/v1.0/analyze?visualFeatures=Categories. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://myUrl.com' is therefore not allowed access. The response had HTTP status code 401. 

Bu benim istek kodudur Ben hurl.it ile isteği test ederken

Header add Access-Control-Allow-Origin "*" 
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type" 
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS" 

o Eserleri. Sadece sunucumdan değil.

+1

Ve hepsi için 'Header set' ile mi? – Croises

cevap

1

Sunucunuz için CORS üstbilgileri ayarlıyorsunuz, bu da birisinin sunucunuza etki alanları arası istekte bulunabileceği anlamına geliyor.

Microsoft Cognitive Services bu üstbilgileri sunucularına eklemeli, böylece etki alanları arası istekte bulunabilmeniz veya JSONP kullanmanız gerekir.

+0

"veya JSONP kullanmalısınız" - Microsoft'un da uygulamak zorunda olduğu. – Quentin