1. 程式人生 > >angularjs post Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.

angularjs post Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.

報錯 lencod pre () ons flight nbsp urlencode 請求參數

現象:

1. angular http 不配置data(請求參數)時不報錯

2. 加上請求參數後,報錯

3. 服務端response.headers().set(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_HEADERS, HttpHeaders.Names.CONTENT_TYPE);後ok

經查:

1. angularjs默認 application/json

2. 無參數不發PreOption請求

3. urlencode不發PreOption請求

angularjs post Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.