JSON与Form POST [英] JSON vs Form POST

查看:109
本文介绍了JSON与Form POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在就将数据发布到REST端点的问题进行一些讨论。由于对象非常复杂,最简单的解决方案是简单地将它们序列化为JSON并在请求体中发送。

We're having a bit of a discussion on the subject of posting data to a REST endpoint. Since the objects are quite complex, the easiest solution is to simply serialize them as JSON and send this in the request body.

现在的问题是:这是犹太人吗?或者是否应将JSON设置为表格参数,如data = [JSON]?或者是在请求体中发送JSON,因为强迫客户端使用该应用程序,通过JavaScript发送数据而不是让浏览器将其打包为 application / x-www-form-urlencoded

Now the question is this: Is this kosher? Or should the JSON be set as a form parameter like data=[JSON]? Or is sending of JSON in the request body just frowned upon for forcing the clients using the application, to send their data via JavaScript instead of letting the browser package it up as application/x-www-form-urlencoded?

我知道所有三个选项工作。但哪些确定?或者至少推荐

I know all three options work. But which are OK? Or at least recommended?

推荐答案

我会说这两种方法都能正常运作
,保持API的一致性非常重要。我个人选择的选项只是将内容发送为 application / json

I'd say that both methods will work well it's important that you stay consistent across your APIs. The option I would personally choose is simply sending the content as application/json.

POST 不会强迫你使用 application / x-www-form-urlencoded - 这只是一个被大量使用的东西,因为它是webbrowsers使用的东西。

POST doesn't force you to use application/x-www-form-urlencoded - it's simply something that's used a lot because it's what webbrowsers use.

这篇关于JSON与Form POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆