request.POST passing JSON data
Distributed load testing framework - Java, Jython, or Clojure scripts.
Brought to you by:
philipa
Hello,
I am using Grinder 3.11 and seeing an issue with request.POST. I hope you can help.
I need to pass image (jpeg, tif) file contents in the JSON body of a HTTP request.
The expected URL request is this:
POST http://localhost:33333/importimage
with JSON body:
{"FileData":"data:image/tiff;base64,<base64 encoded="" data="">}
I can print the JSON data but I am not sure how to pass when JSON data in the HTTP request.</base64>
Below is code snippet I'm trying, however request.POST returns bad request.
response = request.GET(url)
#request.GET is successful.
file = open(filePath, 'r')
data = Codecs.base64Encode(String(file.read()))
file.close()
data = "data:image/jpeg;base64," + data
data = "\"{\"FileData\":\"" + data + ",\"PageSplitting\":true}\""
#print data
headers = [
NVPair('Content-Type', 'application/json'),
NVPair('Content-Type', 'charset=utf-8'),
NVPair('dataType', 'json'),
]
#request.POST fails with bad request
response = request.POST(getCreateImportJobURL(result["SessionID"]), data, headers)
#this fails too
response = request.POST(getCreateImportJobURL(result["SessionID"]), data, [NVPair("Content-type", "application/json"),])
Could you please provide some pointers to help with this issue?
Thank you,
Su