![]() If you get a clear idea of your users, and how they'll make use of your API, then that will help you decide. However, for me it would come down to tool/framework support. through POST or PUT) is much more rare as read-access (in many cases it is data-size: XML very verbose, but usually not an issue when using compression and thinking that the write access case (e.g. ![]() Regarding Restful API over HTTP the most popular content-types I came in touch with are application/xml and application/json. json payload became very popular for transmitting payload for ajax requests). I don't think HTTP is limited to POST in multipart or x-This is also the case for typical HTML representation based webapps (e.g. However, something like "!blob!" will never appear in base64 output. Many choices you see on the net fail this test - the MDN forms docs, for example, use "blob" as a boundary when sending binary data - not good. Now, choose your boundary as a 7-bit ASCII string which cannot appear in base64 output. = is a special case, and may only appear at the end of the encoded output, as a single = or a double =. In base64 3 arbitrary bytes are encoded into four 7-bit characters, where the output character set is (i.e. One simple solution is to use base64 (do not use raw binary). The key is to choose an encoding and a boundary such that your selected boundary characters cannot appear in the encoded output. If you don't choose your boundary correctly, then you will eventually have a problem, whether you're sending plain text or raw binary - the server will find a boundary in the wrong place, and your file will be truncated, or the POST will fail. So, at first sight, multipart/form-data is of no value whatsoever in any file upload, binary or otherwise. The problem with multipart/form-data is that the boundary separator must not be present in the file data (see RFC 2388 section 5.2 also includes a rather lame excuse for not having a proper aggregate MIME type that avoids this problem). This is not a problem for application/x-Inefficient, but it works (and note that the comment about not being able to send filenames as well as binary data is incorrect you just send it as another key/value pair). The key here is that, if you choose to use multipart/form-data, the boundary must not appear in the file data that the server eventually receives. I know this is 3 years too late, but Matt's (accepted) answer is incomplete and will eventually get you into trouble. Why not use multipart/form-data all the time? For short alphanumeric values (like most web forms), the overhead of adding all of the MIME headers is going to significantly outweigh any savings from more efficient binary encoding. The MIME spec gives us more options when representing the value payload - we can choose a more efficient encoding of binary data to save bandwidth (e.g. Each part has its own set of MIME headers like Content-Type, and particularly Content-Disposition, which can give each part its "name." The value piece of each name/value pair is the payload of each part of the MIME message. Parts are separated by a particular string boundary (chosen specifically so that this boundary string does not occur in any of the "value" payloads). With this method of transmitting name/value pairs, each pair is represented as a "part" in a MIME message (as described by other answers). ![]() That's where multipart/form-data comes in. For large binary files, tripling the payload is going to be highly inefficient. That means that for each non-alphanumeric byte that exists in one of our values, it's going to take three bytes to represent it. non-alphanumeric characters are replaced by `%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character MyVariableOne=ValueOne&MyVariableTwo=ValueTwo To understand why, you have to look at what each is doing under the covers.įor application/x-www-form-urlencoded, the body of the HTTP message sent to the server is essentially one giant query string - name/value pairs are separated by the ampersand ( &), and names are separated from values by the equals symbol ( =). Depending on the type and amount of data being transmitted, one of the methods will be more efficient than the other. The purpose of both of those types of requests is to send a list of name/value pairs to the server. The MIME types you mention are the two Content-Type headers for HTTP POST requests that user-agents (browsers) must support. Otherwise, use application/x-www-form-urlencoded. Summary if you have binary (non-alphanumeric) data (or a significantly sized payload) to transmit, use multipart/form-data.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |