Aurelia Web 应用程序调用 azure 移动服务 API 端点

问题描述 投票:0回答:1

我正在创建一个将使用 API 的 Aurelia Web 项目。该 API 作为 Azure 移动服务提供。我知道我需要将 X-ZUMO Auth 标头添加到请求中。但是,当我实例化我的 http 客户端时,根据浏览器开发工具,该标头永远不会进入请求标头。当我在应用程序中运行它时,我会看到一个登录屏幕,我猜是因为 X-ZUMO 标头不是存在,因此应用程序没有运行权限。我正在使用 gulp 运行它,它为我设置了 Web 应用程序的本地实例。我也尝试了外部IP地址。

这是我的课:

import {HttpClient} from 'aurelia-http-client';

export class WebApi
{
static inject = [HttpClient];
constructor(http)
{
    this.http = http;
    this.baseUrl = 'https://myProject.azure-mobile.net/';
    this.zumoHeader = 'X-ZUMO-APPLICATION';
    this.zumoKey = 'zumoKey';
    this.client = new HttpClient()
        .configure(x => {
        x.withBaseUrl(this.baseUrl);
        x.withHeader(this.zumoHeader, this.zumoKey);
    });
}

// requests will go here
testGet()
{
    this.client.jsonp('api/logs?application_id=sessionID&__count=20')
    .then(response =>
    {
        alert(response);
    });
}
}
azure http aurelia azure-mobile-services
1个回答
0
投票

事实证明,在这个实例中你不能使用 jsonp 方法。 get 方法(如果您发出 get 请求)是添加标头的唯一方法。

在此之后,我必须确保服务器也可以处理 CORS。

import {HttpClient} from 'aurelia-http-client';

export class WebApi
{
static inject = [HttpClient];
constructor(http)
{
this.http = http;
this.baseUrl = 'https://myProject.azure-mobile.net/';
this.zumoHeader = 'X-ZUMO-APPLICATION';
this.zumoKey = 'zumoKey';
this.client = new HttpClient()
    .configure(x => {
    x.withBaseUrl(this.baseUrl);
    x.withHeader(this.zumoHeader, this.zumoKey);
});
}

// requests will go here
testGet()
{
this.client.get('api/logs?application_id=sessionID&__count=20')
.then(response =>
{
    alert(response);
});
}
}
© www.soinside.com 2019 - 2024. All rights reserved.