【问题标题】:Custom API call on Azure Mobile App ServiceAzure 移动应用服务上的自定义 API 调用
【发布时间】:2017-05-23 17:23:03
【问题描述】:

我有 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

【问题讨论】:

标签: javascript azure-mobile-services


【解决方案1】:

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

所以你可以把这行代码改成:

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

【讨论】:

  • 谢谢亚伦。你那里有错字。应该是 _client.applicationUrl
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-25
  • 1970-01-01
  • 2020-10-12
  • 2014-03-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多