Vue-resource: how to set charset when set emulateJSON?

Created on 9 Jul 2016  路  2Comments  路  Source: pagekit/vue-resource

I need change the charset to utf-8.

Vue.http.options.emulateJSON = true
// set charset
Vue.http.options.headers = {
  'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
// or 
Vue.http.options.beforeSend = function(request) {
    request.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
};

but on request has data, the 'Content-Type' aways equal application/x-www-form-urlencoded;
1

Most helpful comment

Vue.http.options.emulateHTTP = true
Vue.http.options.headers = {
  'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
Vue.http.interceptors.push((request, next) => {
  let body = request.body
  if (body) {
    let array = []
    for (var key in body) {
      array.push(key + '=' + body[key])
    }
    request.body = array.join('&')
    // ...
  }
})

All 2 comments

Hi.
I've got same problem. I'm using Vuejs + vue-resource with Symfony 3.
Did you already solved this problem ?
Dusan.

Vue.http.options.emulateHTTP = true
Vue.http.options.headers = {
  'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
Vue.http.interceptors.push((request, next) => {
  let body = request.body
  if (body) {
    let array = []
    for (var key in body) {
      array.push(key + '=' + body[key])
    }
    request.body = array.join('&')
    // ...
  }
})
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Creabine picture Creabine  路  3Comments

facesea picture facesea  路  5Comments

ayyobro picture ayyobro  路  3Comments

gbhlwm picture gbhlwm  路  5Comments

mikeyao picture mikeyao  路  6Comments