0

API を使用する Aurelia Web プロジェクトを作成しています。API は、Azure モバイル サービスとして格納されます。X-ZUMO Auth ヘッダーをリクエストに追加する必要があることはわかっています。しかし、http クライアントをインスタンス化すると、ブラウザーの開発ツールに従って、そのヘッダーが要求ヘッダーに到達しません。アプリケーションでこれを実行すると、X-ZUMO ヘッダーではないためと思われるログイン画面が表示されます。存在するため、アプリには実行権限がありません。Web アプリケーションのローカル インスタンスをセットアップする gulp を使用してこれを実行しています。外部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);
    });
}
}
4

1 に答える 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);
});
}
}
于 2015-05-25T17:57:56.687 に答える