changing default Content-Type headers

2,510 views
Skip to first unread message

Vojta Jína

unread,
May 16, 2012, 6:10:00 PM5/16/12
to ang...@googlegroups.com
Hey guys,

we are considering changing default headers for post/put
(Content-Type) from just "application/json" to
"application/json;charset=utf-8".

Could you please double check, that it won't break your apps ?
Especially these apps built with common frameworks like Rails, Django,
etc...

To test it, add this code into your angular app:

someModuleUsedInYourApp.config(function($httpProvider) {
$httpProvider.defaults.headers.put['Content-Type'] =
'application/json;charset=utf-8';
$httpProvider.defaults.headers.post['Content-Type'] =
'application/json;charset=utf-8';
});


Thanks for help,

V.

Eric Jain

unread,
May 18, 2012, 2:38:17 PM5/18/12
to AngularJS
On May 16, 3:10 pm, Vojta Jína <vojta.j...@gmail.com> wrote:
> Could you please double check, that it won't break your apps ?
> Especially these apps built with common frameworks like Rails, Django,
> etc...

Just tested this with Play (2.0.1), doesn't seem to cause any
problems.

Johan

unread,
May 18, 2012, 6:06:39 PM5/18/12
to ang...@googlegroups.com
Tested with ColdFusion 9 and Railo 3 = no problems.

Marcello Nuccio

unread,
May 21, 2012, 8:24:15 AM5/21/12
to ang...@googlegroups.com
Tested with CouchDB 1.2.
No problems.

Vojta Jína

unread,
Jun 7, 2012, 8:13:04 PM6/7/12
to ang...@googlegroups.com
Thank you guys, I'm gonna merge this change.

V.
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/angular/-/PvxgrG-r1eIJ.
>
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/angular?hl=en.

felipe...@gmail.com

unread,
Sep 24, 2012, 4:56:05 PM9/24/12
to ang...@googlegroups.com
Hi,

I'm having problems precisely because of that.

I need to consume an external api that, for some reason, only works if I set the Content-Type header to 'application/xml'. Using 'application/xml; charset=UTF-8' fails.

I already tried to explicitly set this header for the value I want, but I still get this error. This is the example request I'm running on Firefox:

$http({
            url: 'http://api.finder.healthcare.gov/v1.1',
            method: 'POST',
            headers: { 'Content-Type': 'application/xml' },
            data: '<?xml version="1.0" encoding="UTF-8"?>
<PrivateOptionsAPIRequest>
  <CountiesForPostalCodeRequest>
      <ZipCode>20110</ZipCode>
  </CountiesForPostalCodeRequest>
</PrivateOptionsAPIRequest>'
        }) 

I'm not arguing whether this is the best default or not, but what I would expect is that explicitly setting the header the way I'm doing would override this default.
Is there something I can do about it?

felipe...@gmail.com

unread,
Sep 24, 2012, 5:49:42 PM9/24/12
to ang...@googlegroups.com, felipe...@gmail.com
As I'm making more tests, I see this is not an angular issue, it happens the same using jquery or using "manual" ajax. 
Even if I set the content-type header without defining any particular charset, 'utf-8' appears as default.
It seems to be a setting forced by the browser, and too bad that the API I'm trying to use doesn't handle that case.
Reply all
Reply to author
Forward
0 new messages