zoukankan      html  css  js  c++  java
  • Jmeter发送Json请求

    jmeter发送的post请求,可以是json请求,和普通的post请求稍微有点区别,那么怎么用jmeter发送json请求呢?

    首先要找一个json请求的例子,这个例子是携程网搜索机票,

    网址为:http://www.ctrip.com/

    就会看到一个请求

    POST http://flights.ctrip.com/itinerary/api/12808/products HTTP/1.1

    Host: flights.ctrip.com

    Connection: keep-alive

    Content-Length: 394

    Origin: http://flights.ctrip.com

    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36

    Content-Type: application/json

    Accept: */*

    Referer: http://flights.ctrip.com/itinerary/roundtrip/SZX-PVG?date=2018-08-16,2018-09-03&portingToken=f4b3cccf952d430f849b09cf2f1b7142

    Accept-Encoding: gzip, deflate

    Accept-Language: zh-CN,zh;q=0.9,en;q=0.8

    Cookie: _abtest_userid=5de22bed-c5a7-4899-9a39-d9585171b4dd; _RSG=2t4LegTggt55DEOg1rU9yA; _RDG=2832aa1c0f5c9127e73f759be773872d62; _RGUID=5deaa9da-a854-4dc2-af09-7b506a60e345; _ga=GA1.2.928472268.1516689249; Session=SmartLinkCode=U799897&SmartLinkKeyWord=&SmartLinkQuary=&SmartLinkHost=&SmartLinkLanguage=zh; DomesticUserHostCity=SZX|%c9%ee%db%da; adscityen=Shenzhen; _RF1=119.139.197.11; _gid=GA1.2.1823419760.1533784673; Union=OUID=&AllianceID=4897&SID=799897&SourceID=&Expires=1534389473325; MKT_Pagesource=PC; appFloatCnt=1; manualclose=1; _bfa=1.1516689246225.w2exd.1.1533784670751.1533792777877.13.59; _bfs=1.4; Mkt_UnionRecord=%5B%7B%22aid%22%3A%224897%22%2C%22timestamp%22%3A1533794105486%7D%5D; _jzqco=%7C%7C%7C%7C1533794085844%7C1.75043952.1516689249334.1533794085722.1533794105525.1533794085722.1533794105525.undefined.0.0.27.27; __zpspc=9.15.1533794085.1533794105.2%231%7Cbaiduppc%7Cbaidu%7Curldx%7C%25E8%25AE%25A2%25E7%25A5%25A8%25E7%25BD%2591%25E7%25AB%2599%7C%23; _bfi=p1%3D100101991%26p2%3D100101991%26v1%3D59%26v2%3D58; FD_SearchHistorty={"type":"D","data":"D%24%u6DF1%u5733%28SZX%29%24SZX%242018-08-16%24%u4E0A%u6D77%28%u6D66%u4E1C%u56FD%u9645%u673A%u573A%29%28PVG%29%24SHA%2CPVG%242018-09-03%24%24"}

    {"flightWay":"Roundtrip","classType":"ALL","hasChild":false,"hasBaby":false,"searchIndex":1,"portingToken":"f4b3cccf952d430f849b09cf2f1b7142","airportParams":[{"dcity":"SZX","acity":"PVG","dcityname":"深圳","acityname":"浦东国际机场","date":"2018-08-16","dcityid":30},{"dcity":"PVG","acity":"SZX","dcityname":"浦东国际机场","acityname":"深圳","date":"2018-09-03","acityid":30}]}

    可以看出请求数据是一个json字符串,这个就是一个json请求。

    然后在打开jmeter,新建一个http请求

    在http请求中填写内容如下图,把json串复制到BodyData 中去

    添加结果树,执行请求,Response Data没有数据,说明请求不成功

    请求不正常,是因为请求的header 不正确,添加header

    复制请求数据中的header信息到粘贴板,点击【add from clipboard】按钮,就自动把header的键值对复制到这里,很方便。这个是jmeter 4.0,记得jmeter 3.x版本复制过去,每一行开头还多了一个空格,现在4.0 没有这个问题,算是方便不少了。

    再执行请求,请求响应信息正常

    这个时候,如果删除 header信息中的 Content-Type: application/json

    请求又不正常,说明json请求一定要再header 中配置这一项才行

    微信关注公众号:为测,获取更多自动化方面技术文章

  • 相关阅读:
    EntityFramework优缺点
    领导者与管理者的区别
    七个对我最好的职业建议(精简版)
    The best career advice I’ve received
    Difference between Stored Procedure and Function in SQL Server
    2015年上半年一次通过 信息系统项目管理师
    Difference between WCF and Web API and WCF REST and Web Service
    What’s the difference between data mining and data warehousing?
    What is the difference between a Clustered and Non Clustered Index?
    用new创建函数的过程发生了什么
  • 原文地址:https://www.cnblogs.com/testway/p/9448851.html
Copyright © 2011-2022 走看看