如何通过jmeter上传json文件?

时间:2018-01-25 07:32:37

标签: json jmeter performance-testing

我已经记录了我的脚本以通过Jmeter上传json文件,但现在我在通过我本地驱动器上的jmeter上传json文件时遇到了问题。

我已完成以下步骤:

  1. 使用完整路径存档,您可以上传,或将其复制到JMeter" bin"夹
  2. 请勿忘记勾选使用multipart/form-data进行HTTP POST框
  3. 确保提供正确的参数名称和MIME类型
  4. 在我的回复数据中获取异常:

    {"Exception":"Object reference not set to an instance of an object."}
    

2 个答案:

答案 0 :(得分:0)

对我来说就像这样。 JSON example可能是您的服务器更喜欢某些特定标头?例如。内容类型等

为什么你要使用json文件? 如果您在生成随机JSON数据时遇到问题,那么这是一个JSR223预处理器:

import org.apache.commons.io.FileUtils;

def time = vars.get("stratup_time")
File myFile = File.createTempFile("upload-", "" );
// Generate Random length string and write to file

FileUtils.write(myFile, "{\"test\":\"$time\"", "UTF-8" )
// Store file name in variable.
vars.put( "filename", myFile.getCanonicalPath() )

和PostProcessor:

import org.apache.commons.io.FileUtils;
// Delete file and do not throw error
FileUtils.deleteQuietly(new File( vars.get("filename")));

答案 1 :(得分:0)

为了能够记录文件上传事件,您需要将.json文件复制到JMeter" bin"文件夹,这样HTTP(S)测试脚本记录器将能够捕获请求并生成必要的HTTP Request采样器。它还会填充HTTP Header Manager

更多信息:Recording File Uploads with JMeter