Azure 移动应用服务上的自定义 API 调用

Custom API call on Azure Mobile App Service

我有 HTML/JS 客户端尝试访问 Azure 移动应用服务上的 APIController。

以下是我的代码

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

如何去掉URI中的/api

如@rolspace 所述,您需要使用绝对 URL 调用 .invokeApi 函数(必须以 http://https:// 开头)以消除 /api 在 URI 中。

因此您可以将代码行更改为:

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