$http.post seems to double encode data

672 views
Skip to first unread message

Peter Lind

unread,
Jan 27, 2013, 5:04:46 PM1/27/13
to ang...@googlegroups.com
I've got http://jsfiddle.net/yVrqN/1/ which does a basic post using $http. The data it posts contains characters not in the standard ASCII. It seems that somehow Angular thinks the data is not already UTF-8 and then decides to encode it to UTF-8 - which results in double encoding and useless data. It happens in google chrome at least - https://groups.google.com/forum/?fromgroups#!searchin/angular/$24http$20data$20encoding/angular/THwhoOz2DK0/5LUw-fc60kcJ seems to suggest that Firefox might be ok.


The above threads don't have any solutions in them, but I wanted to check if there's a known workaround before I post a bug.

Some extra info: the fiddle above produces this result in chrome

  1. Request URL:
  2. Request Method:
    POST
  3. Status Code:
    200 OK
  4. Request Headersview source
    1. Accept:
      application/json, text/plain, */*
    2. Accept-Charset:
      UTF-8,*;q=0.5
    3. Accept-Encoding:
      gzip,deflate,sdch
    4. Accept-Language:
      en-US,en;q=0.8
    5. Connection:
      keep-alive
    6. Content-Length:
      17
    7. Content-Type:
      application/json;charset=UTF-8
    8. Host:
    9. Origin:
    10. Referer:
    11. User-Agent:
      Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17
    12. X-Requested-With:
      XMLHttpRequest
  5. Request Payload
    1. {"name":"æøå"}
  6. Response Headersview source
    1. Connection:
      keep-alive
    2. Content-Type:
      application/json
    3. Date:
      Sun, 27 Jan 2013 21:14:10 GMT
    4. Server:
      nginx/0.8.54
    5. Transfer-Encoding:
      chunked

Pawel Kozlowski

unread,
Jan 27, 2013, 5:07:59 PM1/27/13
to ang...@googlegroups.com
Hi!

I'm not 100% sure but my impression is that AngularJS doesn't do any character conversions. I would rather suspect encoding settings in a browser. Somehow I would be really, really surprised to find that AngularJS tries to mess with character encoding...

Did you debug through $http to actually see that it is AngularJS that changes encoding?

Cheers,
Pawel

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
 
 



--
Question? Send a fiddle (http://jsfiddle.net/pkozlowski_opensource/Q2NpJ/) or a plunk (http://plnkr.co/)
Need help with jsFiddle? Check this: http://pkozlowskios.wordpress.com/2012/08/12/using-jsfiddle-with-angularjs/

Looking for UI widget library for AngularJS? Here you go: http://angular-ui.github.com/

Peter Lind

unread,
Jan 27, 2013, 5:12:24 PM1/27/13
to ang...@googlegroups.com
Hi, thanks for the answer :)

No, I haven't debugged $http yet - had hoped it was a known issue (which it seems to sort of be, two others have come across it before me at least) and to find the simple explanation of my blunder. I'll give it a try to see if I can find something - perhaps it's a missing charset header from angular that makes chrome think the content is iso-8859-1, and so decides to re-encode it.

Kai Groner

unread,
Jan 28, 2013, 7:01:51 PM1/28/13
to ang...@googlegroups.com
I can reproduce this with just XHR.

However, looking at the bytes in wireshark, I don't see any double encoding.

0000   7b 22 6e 61 6d 65 22 3a 22 c3 a6 c3 b8 c3 a5 22  {"name":"......"
0010   7d                                               }

I think this may just be a problem with webkit inspector.



Kai

Peter Lind

unread,
Jan 29, 2013, 1:37:31 AM1/29/13
to ang...@googlegroups.com
Yeah, some more debugging reveals that the problem lies elsewhere though I have still to figure out where. Turns out my problem is actually in sending the data back to my app.

Anyway, thanks for the help :)

Jean-Philippe Morin

unread,
Mar 28, 2013, 2:27:10 PM3/28/13
to ang...@googlegroups.com
Did you find any solution to this problem? I too have this problem sending my data back to the server.

Horst Müller

unread,
Jul 26, 2013, 4:17:24 AM7/26/13
to ang...@googlegroups.com
Hi everyone,
I have the same problem. Any solutions here? I'm encountering the same problem.
Message has been deleted

Daniela Rodríguez Careri

unread,
Sep 22, 2013, 5:52:32 PM9/22/13
to ang...@googlegroups.com
Same for me, I'm pulling out all my hairs but I can't solve it.
Reply all
Reply to author
Forward
0 new messages