2017-05-23 37 views
0

我有HTML/JS客戶端嘗試訪問Azure移動應用服務上的APIController。Azure移動應用服務上的自定義API調用

以下是我的代碼

var _client = new WindowsAzure.MobileServiceClient("https://myapp.azurewebsites.net/"); 

var pp = _client.invokeApi("/Lookup/GetTransactionType", { 
    body: null, 
    method: "get", 
    parameters: { TenantID: 1 }, 
    headers: { 
     "ZUMO-API-VERSION": "2.0.0", 
     "Content-Type":"application/json", 
     "Cache-Control":"false", 
     "x-zumo-auth": "tada" 
    } 
}).done(function (results) { 
    var message = results.results.count; 
    }, function (error) { 
     alert(error.message) 
    }); 

這裏的問題是,我的API的發佈是這樣的:

https://myapp.azurewebsites.net/Lookup/GetTransactionType?TenantID= {{TenantID}}

,但我得到NOT FOUND客戶端錯誤,因爲它尋找以下URL:

(XHR)GET - https://myapp.azurewebsites.net/api/Lookup/GetTransactionType?TenantID=1

我怎樣才能消除/API在URI?

+1

似乎阻止這種行爲,你需要調用.invokeApi功能與您的要求絕對的URL:http://azure.github .io/azure-mobile-apps-js-client/sdk_src_MobileServiceClient.js.html#line404 – rolspace

回答

1

正如@rolspace提到的,你需要調用.invokeApi功能與絕對URL(必須與http://https://開始),以消除URI中的/api

所以,你可以的代碼行更改爲:

var pp = _client.invokeApi(_client.applicationUrl + "/Lookup/GetTransactionType", { //... 
+1

謝謝Aaron。你在那裏有錯字。應該是* _client.applicationUrl * –

+0

對不起。我已更新。 –

相關問題