x-www-form-urlencoded Vs json HTTP POST [closed] x-www-form-urlencoded Vs json HTTP POST [closed] json json

x-www-form-urlencoded Vs json HTTP POST [closed]


Here you can read similar discussion about formats.

If the structure of encoded data is guaranteed to be a flat list of name-value pairs, x-www-form-urlencoded seems sufficient. If the structure could be (arbitrarily) complex (e.g. nesting lists or associative arrays), then definitely use JSON.

As for me, I'm the KISS adept. In your situation JSON/XML/whatever is extra costs in time, memory and CPU cycles. x-www-form-urlencoded data combine readability and compactness so i can bet it's your choice.


x-www-form-urlencoded and JSON are different things. While x-www-form-urlencoded is simply default content type which used to submit the form to the server, JSON is text-based and human-readable format (standard) which used for serializing and sending structured data over a network connection. You should not compare them.

second one seems to be larger content length, first solution isprobably better?

No, there is no solution labeled as "better". Like pinepain's said, it really depends what kind of data do you send and how to parse / process it. JSON perfectly fits to send additional data with request.

Don't think about the content-length. Think about the data and data structure which you want to send and process it. If you just want to send and process structured data between requests and data-size varies, simply use JSON. It's built for this.

Content-Length difference between two methods wouldn't part of problem since your app is not a Facebook, Twitter or Google like monster. Premature optimisation is root of all evil.