国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

技術(shù)分享 | 接口測(cè)試中如何使用Json 來進(jìn)行數(shù)據(jù)交互 ?

2022-08-01 10:30 作者:愛測(cè)軟件測(cè)試  | 我要投稿

本文節(jié)選自霍格沃茲測(cè)試開發(fā)學(xué)社內(nèi)部教材

json 是一種輕量級(jí)的傳輸數(shù)據(jù)格式,用于數(shù)據(jù)交互。json 請(qǐng)求類型的請(qǐng)求頭中的?Content-Type?對(duì)應(yīng)為?application/json?。碰到這種類型的接口,使用 Java 的 REST Assured 或者 Python 的 Requests 均可解決。


實(shí)戰(zhàn)演示

在 Python 中,使用 json 關(guān)鍵字參數(shù)發(fā)送 json 請(qǐng)求并傳遞請(qǐng)求體信息。

>>> import requests

>>> r = requests.post(

? ?'https://httpbin.ceshiren.com/post',

? ?json = {'key':'value'})

>>> r.request.headers


{'User-Agent': 'python-requests/2.22.0',

'Accept-Encoding': 'gzip, deflate',\

?'Accept': '*/*', 'Connection': 'keep-alive',

?'Content-Length': '16',\

? 'Content-Type': 'application/json'}

如果請(qǐng)求的參數(shù)選擇是json?,那么Content-Type?自動(dòng)變?yōu)?code>application/json?。

在 Java 中,使用contentType()方法添加請(qǐng)求頭信息,使用body()方法添加請(qǐng)求體信息。

import static org.hamcrest.core.IsEqual.equalTo;

import static io.restassured.RestAssured.*;


public class Requests {

? ? public static void main(String[] args) {

? ? ? ? String jsonData = "{\"key\": \"value\"}";

? ? ? ? //定義請(qǐng)求頭信息的contentType為application/json

? ? ? ? given().contentType("application/json").

? ? ? ? ? ? ? ? body(jsonData).

? ? ? ? ? ? ? ? when().

? ? ? ? ? ? ? ? post("https://httpbin.ceshiren.com/post").

? ? ? ? ? ? ? ? then().body("json.key", equalTo("value")).log().all();

? ? }

}



技術(shù)分享 | 接口測(cè)試中如何使用Json 來進(jìn)行數(shù)據(jù)交互 ?的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
盐亭县| 察雅县| 松江区| 家居| 鄯善县| 新闻| 昌黎县| 开原市| 辽源市| 彰武县| 黄山市| 东至县| 无锡市| 大城县| 东丽区| 麦盖提县| 铜川市| 吴江市| 山西省| 育儿| 萍乡市| 赞皇县| 芦溪县| 元氏县| 罗源县| 宁蒗| 武城县| 曲松县| 钟山县| 兴和县| 仁怀市| 廉江市| 山西省| 镶黄旗| 东莞市| 河津市| 盈江县| 五河县| 晋州市| 海宁市| 普兰店市|