0

Tried multiple approaches to send custom-headers via Aurelia-http-client and Aurelia-Fetch-client to pass Headers in the get/post requests that I am making, but in the actual request, the headers are not being passed

approach 1

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

approach 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');
      });

Approach 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
                        }
                    });

        })

But all of them lead to the same error

{ 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' }

At the end we are unbable to pass the headers.

  • Are you sure you're using the instance that has been configured? Show the full code, configuration and call – Fabio Jun 26 '17 at 20:48

1 Answers1

0

it's a security against cross-site scripting (and it's super annoying) @see : Cors Access-Control-Allow-Headers wildcard being ignored?

Benoit Jadinon
  • 1,082
  • 11
  • 21