application/x-www-form-urlencoded or multipart/form-data?

前端 未结 6 1534
無奈伤痛
無奈伤痛 2020-11-21 06:35

In HTTP there are two ways to POST data: application/x-www-form-urlencoded and multipart/form-data. I understand that most browsers are only able t

6条回答
  •  再見小時候
    2020-11-21 06:56

    I agree with much that Manuel has said. In fact, his comments refer to this url...

    http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4

    ... which states:

    The content type "application/x-www-form-urlencoded" is inefficient for sending large quantities of binary data or text containing non-ASCII characters. The content type "multipart/form-data" should be used for submitting forms that contain files, non-ASCII data, and binary data.

    However, for me it would come down to tool/framework support.

    • What tools and frameworks do you expect your API users to be building their apps with?
    • Do they have frameworks or components they can use that favour one method over the other?

    If you get a clear idea of your users, and how they'll make use of your API, then that will help you decide. If you make the upload of files hard for your API users then they'll move away, of you'll spend a lot of time on supporting them.

    Secondary to this would be the tool support YOU have for writing your API and how easy it is for your to accommodate one upload mechanism over the other.

提交回复
热议问题