最近用 Jmeter 发送 PUT 请求,踩了个坑,现记录如下:
难点在在于 body 内有一大串 json 形式的内容
1、PUT 请求的 body 内,直接将 json串传 form-data 形式:
结果:压根执行不过去
2、将抓包出来的请求直接传到 jmeter 里面
id=4&mediaId=4&targetUrl=http%3A%2F%2F121.33.248.251%3A19091%2Ftoutiao¶mJson=%7B%0A++++%22request_id%22%3A+%22201812271802090100120360754600940%22%2C+%0A++++%22api_version%22%3A+%222.1%22%2C+%0A++++%22adslots%22%3A+%5B%0A++++++++%7B%0A++++++++++++%22id%22%3A+%2224e59b06cafb432a%22%2C+%0A++++++++++++%22banner%22%3A+%5B%0A++++++++++++++++%7B%0A++++++++++++++++++++%22width%22%3A+690%2C+%0A++++++++++++++++++++%22height%22%3A+388%2C+%0A++++++++++++++++++++%22pos%22%3A+%22FEED%22%2C+%0A++++++++++++++++++++%22sequence%22%3A+%2221%22%0A++++++++++++++++%7D%0A++++++++++++%5D%2C+%0A++++++++++++%22ad_type%22%3A+%5B%0A++++++++++++++++%22TOUTIAO_FEED_APP_LARGE%22%2C+%0A++++++++++++++++%22TOUTIAO_FEED_LP_LARGE%22%2C+%0A++++++++++++++++%22TOUTIAO_FEED_LP_GIF%22%2C+%0A++++++++++++++++%22TOUTIAO_FEED_APP_VIDEO%22%2C+%0A++++++++++++++++%22TOUTIAO_FEED_LP_VIDEO%22%2C+%0A++++++++++++++++%22TOUTIAO_FEED_APP_SMALL%22%2C+%0A++++++++++++++++%22TOUTIAO_FEED_LP_SMALL%22%2C+%0A++++++++++++++++%22TOUTIAO_FEED_LP_GROUP%22%2C+%0A++++++++++++++++%22TOUTIAO_FEED_APP_GROUP%22%0A++++++++++++%5D%2C+%0A++++++++++++%22bid_floor%22%3A+5000%2C+%0A++++++++++++%22pmp%22%3A+%7B%0A++++++++++++++++%22deals%22%3A+%5B%0A++++++++++++++++++++%7B%0A++++++++++++++++++++++++%22id%22%3A+190411%2C+%0A++++++++++++++++++++++++%22bid_floor%22%3A+5000%2C+%0A++++++++++++++++++++++++%22new_id%22%3A+190411%0A++++++++++++++++++++%7D%0A++++++++++++++++%5D%0A++++++++++++%7D%2C+%0A++++++++++++%22channel_id%22%3A+0%2C+%0A++++++++++++%22advanced_creative_type%22%3A+%5B%0A++++++++++++++++%22NONE%22%2C+%0A++++++++++++++++%22ACTION%22%2C+%0A++++++++++++++++%22DISCOUNT%22%0A++++++++++++%5D%0A++++++++%7D%0A++++%5D%2C+%0A++++%22app%22%3A+%7B%0A++++++++%22id%22%3A+%2213%22%2C+%0A++++++++%22name%22%3A+%22news_article%22%2C+%0A++++++++%22ver%22%3A+%22704%22%2C+%0A++++++++%22scheme%22%3A+%22snssdk+143%3A%2F%2F%22%0A++++%7D%2C+%0A++++%22device%22%3A+%7B%0A++++++++%22dnt%22%3A+false%2C+%0A++++++++%22ua%22%3A+%22Dalvik%2F2.1.0+(Linux%3B+U%3B+Android+8.0.0%3B+VTR-AL00+Build%2FHUAWEIVTR-AL00)+NewsArticle%2F7.0.4+cronet%2FTTNetVersion%3Aa729d5c3+2018-11-25%22%2C+%0A++++++++%22ip%22%3A+%22223.104.64.206%22%2C+%0A++++++++%22geo%22%3A+%7B%0A++++++++++++%22lat%22%3A+23.09559%2C+%0A++++++++++++%22lon%22%3A+113.36527%2C+%0A++++++++++++%22city%22%3A+%22%5C%5C345%5C%5C271%5C%5C277%5C%5C345%5C%5C267%5C%5C236%22%0A++++++++%7D%2C+%0A++++++++%22device_id_md5%22%3A+%226e8a6e9bb09fb6cd5140ca6c9a8d6ef7%22%2C+%0A++++++++%22make%22%3A+%22unknown%22%2C+%0A++++++++%22model%22%3A+%22VTR-AL00%22%2C+%0A++++++++%22os%22%3A+%22android%22%2C+%0A++++++++%22osv%22%3A+%228.0.0%22%2C+%0A++++++++%22connection_type%22%3A+%22NT_4G%22%2C+%0A++++++++%22device_type%22%3A+%22PHONE%22%2C+%0A++++++++%22android_id_md5%22%3A+%226df357ed0dacf593c444a7e4ee01b81f%22%0A++++%7D%2C+%0A++++%22user%22%3A+%7B%0A++++++++%22id%22%3A+%220%22%2C+%0A++++++++%22yob%22%3A+%2224%22%2C+%0A++++++++%22gender%22%3A+%22MALE%22%0A++++%7D%2C+%0A++++%22dsp_id%22%3A+190411%2C+%0A++++%22merge_dsp_ids%22%3A+%5B%0A++++++++190411%0A++++%5D%2C+%0A++++%22req_audit_type%22%3A+%22AUDIT_FIRST%22%2C+%0A++++%22new_dsp_id%22%3A+190411%2C+%0A++++%22new_merge_dsp_ids%22%3A+%5B%0A++++++++190411%0A++++%5D%0A%7D
发现是一大坨,想参数化?改的你想死
那么有啥方法可以既美观大方,又能发成请求呢?
方法:浏览器 f12
利用这个,我们在 jmeter 内,改写请求:
参数全部写在消息体内,各个 key-value 用 & 连接,这样大的 json 串不会成乱码形式,而且请求成功
id=4&mediaId=4&targetUrl=http://121.33.248.251:19091/toutiao¶mJson={
"request_id": "",
"api_version": "2.1",
"adslots": [
{
"id": "24e59b06cafb432a",
"banner": [
{
"width": 690,
"height": 388,
"pos": "FEED",
"sequence": ""
……
响应结果:
完事