我们有一个服务于Aurelia静态文件和API的Web服务器,服务器受NTLM保护(在OWIN上使用集成Windows身份验证).
使用Aurelia Fetch Client时,我们可以成功点击API而不会出现问题.这是我们使用的配置:
constructor(private http: HttpClient){
http.configure(config => {
config
.withBaseUrl('api/')
.useStandardConfiguration();
});
Run Code Online (Sandbox Code Playgroud)
但是,当我们使用Aurelia Fetch Client时,我们得到了401 (Unauthorized)(似乎缺少授权标头)
constructor(private client: HttpClient) {
client.configure(cfg => {
cfg
.withBaseUrl('http://localhost:80/api/someEndpoint')
.withDefaults({
headers: {
'Accept' : 'application/json',
'X-Requested-With': 'Fetch'
}
})
Run Code Online (Sandbox Code Playgroud)
关于如何解决这个问题的任何想法都非常感谢.
aurelia aurelia-fetch-client aurelia-http-client aurelia-framework
当我使用aurelia-fetch-client将json数据发布到服务器时,出现此错误“ TypeError:尝试获取资源时出现NetworkError”。我认为您的回答对我非常有用。
post.html
<template>
<section>
<form role="form" submit.trigger="signup()">
<div class="form-group">
<label for="OrganisationId">OrganisationId</label>
<input type="text" value.bind="organisationId" placeholder="OrganisationId">
</div>
<div >
<label for="OrganisationName">OrganisationName</label>
<input type="OrganisationName" value.bind="organisationName" placeholder="Password">
</div>
<button type="submit" class="btn btn-default">Enter</button>
</form>
</section>
</template>
Run Code Online (Sandbox Code Playgroud)post.js
import 'fetch';
import { HttpClient, json } from 'aurelia-fetch-client';
let httpClient = new HttpClient();
export class signup {
heading1 = "Welome to User";
organisationId = "";
organisationName = "";
signup() {
alert("calliong");
var myUser1 = { organisationId: this.organisationId, organisationName: this.organisationName }
console.log(myUser1);
httpClient.fetch('http://172.16.0.26:8085/employee-management/rest/employees/addOrganisations', {
method: "POST", …Run Code Online (Sandbox Code Playgroud)我有一个名为Infrastructure的类,我认为它可以很方便地继承HttpClient.这个类公开了get,post,put和delete的方法.
import {Aurelia} from "aurelia-framework";
import {HttpClient, json} from "aurelia-fetch-client";
export default class Infrastructure extends HttpClient {
get(url, queryString, contentType) {
//..
}
post(url, data, contentType) {
//..
}
put(url, data, contentType) {
//..
}
delete(url, contentType) {
//..
}
}
Run Code Online (Sandbox Code Playgroud)
我的想法是,我现在可以拥有注入的服务,Infrastructure他们可以调用configure基础设施
import {inject} from "aurelia-framework";
import Infrastructure from "./infrastructure";
@inject(Infrastructure)
export class InventoryService {
constructor (infrastructure) {
infrastructure.configure(config => {
config
.useStandardConfiguration()
.withBaseUrl(`http://localhost:64441/inventory`);
});
this.infrastructure = infrastructure;
}
}
Run Code Online (Sandbox Code Playgroud)
我有几个使用Infrastructure这样的服务,一切正常.问题是我不需要将两个 …
javascript dependency-injection ecmascript-6 aurelia aurelia-http-client