【问题标题】:Aurelia http-client/http-fetch not sending headersAurelia http-client/http-fetch 不发送标头
【发布时间】:2017-11-27 23:53:25
【问题描述】:

尝试了多种方法通过 Aurelia-http-client 和 Aurelia-Fetch-client 发送自定义标头,以在我正在发出的 get/post 请求中传递标头,但在实际请求中,标头没有被传递

接近 1

var client = new HttpClient()
client.createRequest('/api/information/save')
  .asPost()
  .withBaseUrl('http://10.0.0.13:3000')
  .withHeader("X-auth-code", "abc")
  .send()

方法 2

var client = new HttpClient()
      .configure(x => {
        x.withBaseUrl('http://10.0.0.13:3000');
        x.withCredentials(true);
        x.withHeader('Content-Type', 'application/json; charset=utf-8');
        x.withHeader('x-client-code', 'abc');
      });

方法3

this.http.configure(config => {
            config
                .withDefaults({
                        credentials: 'same-origin',
                        headers: {
                            "Content-Type": "application/json",
                            "x-client-code": "abc",

                        }
                    })
                .useStandardConfiguration()
                    .withInterceptor({
                        request(request) {
                    request.headers.append("x-client-code","abc");
                            console.log(`${request.headers}`);
                            return request; // you can return a modified Request, or you can short-circuit the request by returning a Response
                        },
                        response(response) {
                            console.log(`Received ${response.status} ${response.url}`);
                            return response; // you can return a modified Response
                        }
                    });

        })

但所有这些都会导致相同的错误

{ host: '10.0.0.13:3000',
  connection: 'keep-alive',
  'access-control-request-method': 'POST',
  origin: 'http://localhost:9000',
  'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.104 Safari/537.36',
  'access-control-request-headers': 'content-type',
  accept: '*/*',
  referer: 'http://localhost:9000/',
  'accept-encoding': 'gzip, deflate',
  'accept-language': 'en-GB,en-US;q=0.8,en;q=0.6' }

最后我们无法传递标头。

【问题讨论】:

  • 您确定使用的是已配置的实例吗?显示完整代码、配置和调用

标签: aurelia-fetch-client aurelia


【解决方案1】:

这是针对跨站点脚本的安全措施(而且非常烦人)@see : Cors Access-Control-Allow-Headers wildcard being ignored?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    • 1970-01-01
    • 2018-03-11
    • 2018-10-09
    相关资源
    最近更新 更多