when instantiate vuejs (2.2.6) , vue-resource (1.2.1), set header authorization following code, way can authorize requests api:
vue.http.headers.common.authorization = 'bearer ...';
however, want make request third party api, , not want authorization
field sent. additionally, api not allow use authorization header.
let cep = ''; this.$http.get('https://viacep.com.br/ws/' + cep + '/json') .then(response => { console.log(response.headers); });
this way authorization field sent header, on access-control-request-headers:
i tried remove header fields following codes, without success.
this.$http.headers.common.authorization = null; this.$http.headers.common['access-control-allow-headers'] = null; this.$http.get('https://viacep.com.br/ws/' + cep + '/json') .then(response => { console.log(response.headers); });
in vue-resource
documentation, there possibility of inserting object force request configuration, documentation isn't complete.
this.$http.get('https://viacep.com.br/ws/' + cep + '/json', { ...here... }).then(response => { console.log(response.headers); });
is there way remove authorization field, or other field given request?
thanks.
* updated *
by using interceptors (as in below sample) i can edit request i can not delete particular field.
vue.http.interceptors.push((request, next) => { const viacep = request.url.includes('viacep.com.br'); if (viacep) { request.headers.set('authorization', 'try this'); } next(response => {}); });
try delete:
vue.http.interceptors.push((request, next) => { const viacep = request.url.includes('viacep.com.br'); if (viacep) { request.headers.delete('authorization'); } next(response => {}); });
use interceptor, inspect request, , remove header if needed.
vue.http.interceptors.push(function(request, next) { const removeauthheaders = request.url.includes("viacep.com.br"); if (removeauthheaders){ request.headers.delete('access-control-allow-headers') request.headers.delete('authorization') } else { request.headers.set('access-control-allow-headers', <value>) request.headers.set('authorization', <value>) } next(); });
Comments
Post a Comment