cordova - How to set Content-Type header in cordovaHTTP plugin requests -


i'm trying use cordovahttp plugin , in post api calls, although i've set content-type header application/json can see content sent in application/x-www-form-urlencoded format , no content-type header exist in headers of request.

usage sample:

cordovahttp.post("url/to/method",  {    "email": "ali@aliha.me"  },  {    "content-type": "application/json"  },  function (result) {    alert('success');  },  function (error) {    alert('error');  }); 

in server api see:

raw body email=ali%40aliha.me 

how can set content-type header?

note: approach of setting headers, works other headers authorization header.

no mention in plugin automatically encodes request body per set "content-type". need yourself.

also, seems there's no straight forward way send data in request body without specifying key.value pair.

that's plugin documentation

/**    * write values in map form data request body    * <p>    * pairs specified url-encoded in utf-8 , sent    * 'application/x-www-form-urlencoded' content-type    *    * @param values    * @return request    * @throws httprequestexception    */   public httprequest form(final map<?, ?> values) throws httprequestexception {     return form(values, charset_utf8);   } 

you can encode json string way have figure way send in request body

var jsondata = json.stringify({"email": "ali@aliha.me"}); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -