首页 文章

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

提问于
浏览
0

我有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={}

但是我在客户端找到NOT FOUND错误,因为它寻找以下URL:

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

如何消除URI中的 /api

1 回答

  • 1

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

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

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

相关问题