最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

postman模擬post請(qǐng)求的四種請(qǐng)求體

 更新時(shí)間:2022年01月07日 15:33:30   作者:孤獨(dú)的行走  
本文主要介紹了postman模擬post請(qǐng)求的四種請(qǐng)求體,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

1.application/x-www-form-urlencoded

瀏覽器的原生 表單,其中ajax也是用這種方式提交的,主要是key-value 鍵值對(duì)的形式。一般的請(qǐng)求方式如下圖所示:

這是在這里插入圖片描述

POST  HTTP/1.1
Host: test.app.com
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache
Postman-Token: e00dbaf5-15e8-3667-6fc5-48ee3cc89758

key1=value1&key2=value2

POST中(application/x-www-form-urlencoded)請(qǐng)求方式截圖,主要在key中傳入接口中定義的變量,value 中傳入值就可以進(jìn)行測試接口

2.multipart/form-data

它會(huì)將表單的數(shù)據(jù)處理為一條消息,以標(biāo)簽為單元,用分隔符分開。既可以上傳鍵值對(duì),也可以上傳文件。
由于有boundary隔離,所以multipart/form-data既可以上傳文件,也可以上傳鍵值對(duì),它采用了鍵值對(duì)的方式,所以可以上傳多個(gè)文件,在springmvc中可以使用MultipartHttpServletRequest接收通過api根據(jù)"name"獲取不同的鍵值,也可以通過MulTipartFile數(shù)組接收多個(gè)文件
。

POST  HTTP/1.1
Host: test.app.com
Cache-Control: no-cache
Postman-Token: 59227787-c438-361d-fbe1-75feeb78047e
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="filekey"; filename=""
Content-Type: 


------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="textkey"

tttttt
------WebKitFormBoundary7MA4YWxkTrZu0gW--

在這里插入圖片描述

在這里插入圖片描述

PSOT同時(shí)上傳文件和鍵值對(duì)數(shù)據(jù)

3. raw

可以上傳任意格式的文本,可以上傳text、json、xml、html等Controller接口可以通過@RequestBody 來修飾,傳入數(shù)據(jù)就是JSON格式

注意: 在使用raw 方式,如果在PostMan再測試的時(shí)候需要在headers中添加一個(gè)key-value (Content-Type: application/json 或者對(duì)應(yīng)的格式)

在這里插入圖片描述

4.binary

相當(dāng)于Content-Type:application/octet-stream,從字面意思得知,只可以上傳二進(jìn)制數(shù)據(jù),通常用來上傳文件,由于沒有鍵值,所以,一次只能上傳一個(gè)文件。

在這里插入圖片描述

POST  HTTP/1.1
Host: test.app.com
Cache-Control: no-cache
Postman-Token: 5ad66f08-6faa-aba0-744a-ca958b1a0fc2

undefined

 提醒:
multipart/form-data與x-www-form-urlencoded區(qū)別:
  html中的form 表單有兩種:application/x-www-form-urlencoded和multipart/form-data。application/x-www-form-urlencoded是默認(rèn)的MIME內(nèi)容編碼類型,它在傳輸比較大的二進(jìn)制或者文本數(shù)據(jù)時(shí)效率極低。

MIME:
簡單說,MIME類型就是設(shè)定某種擴(kuò)展名的文件用一種應(yīng)用程序來打開的方式類型。服務(wù)器會(huì)將它們發(fā)送的多媒體數(shù)據(jù)的類型告訴瀏覽器,而通知手段就是說明該多媒體數(shù)據(jù)的MIME類型,服務(wù)器將 MIME標(biāo)志符放入傳送的數(shù)據(jù)中來告訴瀏覽器使用哪種插件讀取相關(guān)文件。

multipart/form-data:既可以上傳文件等二進(jìn)制數(shù)據(jù),也可以上傳表單鍵值對(duì),只是最后會(huì)轉(zhuǎn)化為一條信息。當(dāng)設(shè)置multipart/form-data,http會(huì)忽略 contentType 屬性。

x-www-form-urlencoded:只能上傳鍵值對(duì),不能用于文件上傳。不同的field是用&區(qū)分開的。這兩個(gè)類均實(shí)現(xiàn)了HttpEntity接口,使用如下:

public static String testUpload(String url) {
? ? ? ? String result = null;
? ? ? ? CloseableHttpClient httpclient = HttpClients.createDefault();
? ? ? ? HttpPost httppost = new HttpPost(url);
? ? ? ? try {
? ? ? ? ? ? FileBody bin = new FileBody(new File("F:\\image\\sendpix0.jpg"));
? ? ? ? ? ? StringBody comment = new StringBody("A binary file of some kind", ContentType.TEXT_PLAIN);
? ? ? ? ? ? HttpEntity reqEntity = MultipartEntityBuilder.create().addPart("bin", bin).addPart("comment", comment)
? ? ? ? ? ? ? ? ? ? .build();
? ? ? ? ? ? httppost.setEntity(reqEntity);
? ? ? ? ? ? System.out.println("executing request " + httppost.getRequestLine());
? ? ? ? ? ? CloseableHttpResponse response = httpclient.execute(httppost);
? ? ? ? ? ? try {
? ? ? ? ? ? ? ? int statusCode = response.getStatusLine().getStatusCode();
? ? ? ? ? ? ? ? if (statusCode == HttpStatus.SC_OK) {
? ? ? ? ? ? ? ? ? ? result = EntityUtils.toString(response.getEntity(), "UTF-8");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? } finally {
? ? ? ? ? ? ? ? response.close();
? ? ? ? ? ? ? ? httpclient.close();
? ? ? ? ? ? }
? ? ? ? } catch (ClientProtocolException e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? } catch (IOException e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? } finally {
? ? ? ? ? ? try {
? ? ? ? ? ? ? ? httpclient.close();
? ? ? ? ? ? } catch (IOException e) {
? ? ? ? ? ? ? ? e.printStackTrace();
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return result;
? ? }

? ? public static String testParam(String url) {
? ? ? ? String result = null;
? ? ? ? CloseableHttpClient httpclient = HttpClients.createDefault();
? ? ? ? httpclient = HttpsHelper.newHttpsCloseableClient();
? ? ? ? HttpPost httpPost = new HttpPost(url);
? ? ? ? List<NameValuePair> params = new ArrayList<NameValuePair>();
? ? ? ? params.add(new BasicNameValuePair("key1", "value1"));
? ? ? ? params.add(new BasicNameValuePair("key2", "value2"));
? ? ? ? try {
? ? ? ? ? ? httpPost.setEntity(new UrlEncodedFormEntity(params));
? ? ? ? ? ? httpPost.setConfig(requestConfig);
? ? ? ? ? ? CloseableHttpResponse httpResp = httpclient.execute(httpPost);
? ? ? ? ? ? try {
? ? ? ? ? ? ? ? int statusCode = httpResp.getStatusLine().getStatusCode();
? ? ? ? ? ? ? ? if (statusCode == HttpStatus.SC_OK) {
? ? ? ? ? ? ? ? ? ? result = EntityUtils.toString(httpResp.getEntity(), "UTF-8");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? } finally {
? ? ? ? ? ? ? ? httpResp.close();
? ? ? ? ? ? ? ? httpclient.close();
? ? ? ? ? ? }
? ? ? ? } catch (UnsupportedEncodingException e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? } catch (ClientProtocolException e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? } catch (IOException e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? } finally {
? ? ? ? ? ? try {
? ? ? ? ? ? ? ? httpclient.close();
? ? ? ? ? ? } catch (IOException e) {
? ? ? ? ? ? ? ? e.printStackTrace();
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return result;
? ? }

到此這篇關(guān)于postman模擬post請(qǐng)求的四種請(qǐng)求體的文章就介紹到這了,更多相關(guān)postman post請(qǐng)求內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 關(guān)于提交項(xiàng)目到gitee報(bào)錯(cuò)Push to origin/master was rejected的問題

    關(guān)于提交項(xiàng)目到gitee報(bào)錯(cuò)Push to origin/master was rejected的問題

    這篇文章主要介紹了提交項(xiàng)目到gitee報(bào)錯(cuò)Push to origin/master was rejected的解決辦法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-10-10
  • git clone下來的代碼如何放在指定路徑

    git clone下來的代碼如何放在指定路徑

    這篇文章主要介紹了git clone下來的代碼如何放在指定路徑,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • Git安裝詳細(xì)圖文教程(Git?安裝過程的每一個(gè)步驟)

    Git安裝詳細(xì)圖文教程(Git?安裝過程的每一個(gè)步驟)

    這篇文章主要介紹了Git安裝詳細(xì)圖文教程(Git?安裝過程的每一個(gè)步驟),本文以Git-2.35.1.2-64-bit.exe為例給大家講解安裝過程,需要的朋友可以參考下
    2023-02-02
  • 性能測試QPS+TPS+事務(wù)基礎(chǔ)知識(shí)分析

    性能測試QPS+TPS+事務(wù)基礎(chǔ)知識(shí)分析

    本篇文章是性能測試基礎(chǔ)篇,主要介紹了性能測試中對(duì)QPS+TPS+事務(wù)的基礎(chǔ)知識(shí)分析,有需要的朋友可以借鑒參考下,希望可以對(duì)廣大讀者有所幫助
    2021-09-09
  • Git中使用.gitignore忽略文件的推送方式

    Git中使用.gitignore忽略文件的推送方式

    這篇文章主要介紹了Git中使用.gitignore忽略文件的推送方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-02-02
  • vscode中setting.json配置文件配置詳解

    vscode中setting.json配置文件配置詳解

    這篇文章主要給大家介紹了關(guān)于vscode中setting.json配置文件配置的相關(guān)資料,VSCode中的setting.json文件用于存儲(chǔ)用戶自定義的配置設(shè)置,文中給出了詳細(xì)的代碼示例,需要的朋友可以參考下
    2023-09-09
  • flash 擋住層的解決方法

    flash 擋住層的解決方法

    使用層制作的下拉菜單下正好有FLASH動(dòng)畫,菜單被動(dòng)畫遮擋.
    2009-08-08
  • linux系統(tǒng)使用vscode進(jìn)行qt開發(fā)的過程分享

    linux系統(tǒng)使用vscode進(jìn)行qt開發(fā)的過程分享

    最近在Linux上搞Qt,搞的一頭霧水,小編把整個(gè)過程記錄下,分享需要的朋友,如果大家對(duì)linux系統(tǒng)使用vscode進(jìn)行qt開發(fā)相關(guān)知識(shí)感興趣的朋友跟隨小編一起看看吧
    2021-12-12
  • 詳解Git建立本地倉庫的兩種方法

    詳解Git建立本地倉庫的兩種方法

    這篇文章主要介紹了詳解Git建立本地倉庫的兩種方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • Matlab操作HDF5文件示例

    Matlab操作HDF5文件示例

    這篇文章主要為大家介紹了Matlab操作HDF5文件示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-06-06

最新評(píng)論

天峨县| 蒲城县| 新乡县| 长白| 灯塔市| 芜湖县| 珲春市| 东辽县| 大化| 合作市| 临沧市| 玉山县| 临泉县| 固阳县| 延长县| 泰宁县| 万荣县| 营山县| 林甸县| 鄯善县| 嘉鱼县| 宁德市| 理塘县| 上虞市| 佛教| 新邵县| 大荔县| 根河市| 鄄城县| 凤冈县| 额济纳旗| 万山特区| 湖北省| 波密县| 临西县| 金华市| 灵宝市| 灵台县| 长宁区| 诸城市| 全州县|