这里使用 MIME 类型作为 Multipart/form-data 和参数作为 spb 的 POST 请求我正在传递 1 个具有完整 JSON 正文的文本文件。
text file : upload.txt
{
"id":"Rx2160C-019A",
"iAgree":false,
"price":"31.25",
"maxDispenceDays":null,
"RxId":"DRAFT9800E",
.......
}
每次我需要根据最后一个 HTTP 请求更新文本文件中的id
and时。RxId
我正在尝试使用BeanShell PostProcessor
元素,但我没有得到适当的代码和解决方案。
f = new FileOutputStream("/Users/bhkuma/Documents/Bharath/Jmeter/LoadTesting/goRxDigitize.txt", true);
p = new PrintStream(f);
this.interpreter.setOut(p);
print(name + "," + email);
f.close();
我怎样才能做到这一点?
这是我正在尝试的更新代码..
import java.io.File;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;
import java.io.BufferedReader;
import org.json.JSONException;
import org.json.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
//ObjectMapper mapper = new ObjectMapper();
//JSONObject root = mapper.readValue(new File("/Users/bhkuma/Documents/Bharath/Jmeter/LoadTesting/upload.txt"), JSONObject.class);
FileReader fr = new FileReader("/Users/bhkuma/Documents/Bharath/Jmeter/LoadTesting/upload.txt");
BufferedReader br = new BufferedReader(fr);
String sCurrentLine;
String output="";
while ((sCurrentLine = br.readLine()) != null) {
output += sCurrentLine;
//System.out.println(sCurrentLine);
}
log.info("bharath");
log.info(output);
JSONObject obj = new JSONObject(output);
JSONObject value = new JSONObject();
value.put("id","Rx2160C-100A");
log.info(value);
obj.put(value);
log.info(output);
System.out.println("Successfully updated json object to file...!!");
而这里的 JSON 对象将无法工作......