“请求有效载荷”与“请求有效载荷”有什么区别? vs“表单数据”如Chrome开发工具“网络”选项卡中所示 [英] What's the difference between "Request Payload" vs "Form Data" as seen in Chrome dev tools Network tab

查看:1102
本文介绍了“请求有效载荷”与“请求有效载荷”有什么区别? vs“表单数据”如Chrome开发工具“网络”选项卡中所示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我填写表格并提交后,选中网络在Chrome中我看到请求有效载荷,我通常会看到表单数据。这两者之间的区别是什么,什么时候会发送一个而不是另一个?



谷歌搜索这个,但没有真正找到任何信息解释这一点(只是人们试图以获取JavaScript应用程序发送表单数据而不是请求有效载荷。 解决方案

请求有效载荷 - 精确: HTTP请求的有效内容主体
- 通常通过 POST或PUT请求发送的数据。
这是标题之后的部分和 HTTP的 CRLF 请求



具有 Content-Type:application / json 的请求可能如下所示:

  POST / some-path HTTP / 1.1 
Content-Type:application / json

{foo:bar,name:John }

如果您通过AJAX提交,浏览器会简单地向您显示它作为有效内容正在提交的内容。这是它所能做到的,因为它不知道数据来自何处。



如果您使用 method =POST提交HTML表单 Content-Type:application / x-www-form-urlencoded Content-Type:multipart / form-数据您的请求可能如下所示:

  POST / some-path HTTP / 1.1 
Content-Type:application / x-www-form-urlencoded

foo = bar& name = John

在这种情况下,表单数据是请求负载。这里浏览器知道更多:它知道bar是提交表单的输入域foo的值。这就是它向你展示的内容。



因此,它们在 Content-Type 中有所不同,但不在提交方式数据。在这两种情况下,数据都在消息体中。 Chrome可以区分开发者工具中的数据呈现方式。

I have an old web application I have to support (which I did not write).

When I fill out a form and submit then check the "Network" tab in Chrome I see "Request Payload" where I would normally see "Form Data". What is the difference between the two and when would one be sent instead of the other?

Googled this, but didn't really find any info explaining this (just people trying to get javascript apps to send "Form Data" instead of "Request Payload".

解决方案

The Request Payload - or to be more precise: payload body of a HTTP Request - is the data normally send by a POST or PUT Request. It's the part after the headers and the CRLF of a HTTP Request.

A request with Content-Type: application/json may look like this:

POST /some-path HTTP/1.1
Content-Type: application/json

{ "foo" : "bar", "name" : "John" }

If you submit this per AJAX the browser simply shows you what it is submitting as payload body. That’s all it can do because it has no idea where the data is coming from.

If you submit a HTML-Form with method="POST" and Content-Type: application/x-www-form-urlencoded or Content-Type: multipart/form-data your request may look like this:

POST /some-path HTTP/1.1
Content-Type: application/x-www-form-urlencoded

foo=bar&name=John

In this case the form-data is the request payload. Here the Browser knows more: it knows that bar is the value of the input-field foo of the submitted form. And that’s what it is showing to you.

So, they differ in the Content-Type but not in the way data is submitted. In both cases the data is in the message-body. And Chrome distinguishes how the data is presented to you in the Developer Tools.

这篇关于“请求有效载荷”与“请求有效载荷”有什么区别? vs“表单数据”如Chrome开发工具“网络”选项卡中所示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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