1. 百度到很多关于 jmeter put 方法的使用 , 但觉得都完全 下面我大致总结下 ;
>1. 放入 url 中 如: www.*****.com?a=1&b=2 ;
>2. 放入到 parameters 的值中 名称为空 ;
>3. 添加 Content-Type :application/JSON 或者 application/x-www-form-urlencoded
以下是 jmeter 官网给出的说明:
- define the body as a file with empty Parameter name field; in which case the MIME Type is used as the Content-Type
- define the body as parameter value(s) with no name
- use the Body Data tab
在结合这篇博文我们就看懂了
问题 :HTTP 请求中 request payload 和 formData 区别?
1.FormData 和 Payload 是浏览器传输给接口的两种格式, 这两种方式浏览器是通过 Content-Type 来进行区分的 (了解 Content-Type http://www.cnblogs.com/tugenhua0707/p/8975121.html ), 如果是 application/x-www-form-urlencoded 的话, 则为 formdata 方式, 如果是 application/JSON 或 multipart/form-data 的话, 则为 request payload 的方式.
比如如下使用 Ajax 方式的提交 post 请求的代码 (默认使用 application/x-www-form-urlencoded 编码):
- <!DOCTYPE HTML>
- <HTML>
- <head>
- <title>
- </title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
- <script type="text/javascript" src="https://tugenhua0707.github.io/html5UploadImage/js/jquery.js">
- </script>
- </head>
- <body>
- <div id="app">
- <div class="btn">
- 发送 post 请求
- </div>
- </div>
- <script>
- var obj = {
- "name": 'CntChen',
- "info": 'Front-End',
- };
- $('.btn').click(function() {
- $.Ajax({
- url: 'www.example.com',
- type: 'POST',
- dataType: 'json',
- data: obj,
- success: function(d) {}
- })
- });
- </script>
- </body>
- </HTML>
如下图所示:
2. 使用 multipart/form-data 表单上传文件
- <!DOCTYPE HTML>
- <HTML>
- <head>
- <title>
- </title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
- </head>
- <body>
- <div id="app">
- <form action="http://www.example.com" method="POST" enctype="multipart/form-data">
- <p>
- username:
- <input type="text" name="fname" />
- </p>
- <p>
- age:
- <input type="text" name="age" />
- </p>
- <input type="submit" value="提交" />
- </form>
- </div>
- </body>
- </HTML>
如下图所示:
可以看到 使用 multipart/form-data 表单上传文件时使用的是 Request Payload 格式;
3. 使用 Content-Type: application/JSON 来编码
如下 HTML 代码:
- <!DOCTYPE HTML>
- <HTML>
- <head>
- <title>
- </title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
- <script type="text/javascript" src="https://tugenhua0707.github.io/html5UploadImage/js/jquery.js">
- </script>
- </head>
- <body>
- <div id="app">
- <div class="btn">
- 发送 post 请求
- </div>
- </div>
- <script>
- $('.btn').click(function() {
- $.Ajax({
- url: 'http://localhost:8081/api.json',
- type: 'POST',
- dataType: 'json',
- contentType: 'application/json',
- data: JSON.stringify({
- a: [{
- b: 1,
- a: 1
- }]
- }),
- success: function(d) {}
- })
- });
- </script>
- </body>
- </HTML>
- View Code
如下图所示
说明: 文章借鉴与: https://www.cnblogs.com/tugenhua0707/p/8975615.html
来源: http://www.bubuko.com/infodetail-2848938.html