0

I need to send files with a webservice request. But I don't know how to specify the file int the WebService(SOAP) Request.

How can I do that? Or is it possible to use the HTTP Request?

Thanks in advance...

SLo
  • 75
  • 1
  • 1
  • 10

1 Answers1

0

JMeter provides at least 2 options on how you can pass a file to a sampler, function or whatever.

Option 1: __FileToString() function. Just put it into your "SOAP/XML-RPC Data" textarea as follows:

${__FileToString(/path/to/your/file.xml,,)}

Option 2: Another, more flexible option is reading file via scripting extension (i.e. if XML file encoding is different from your current system encoding and becomes corrupted).

Add a Beanshell Pre Processor as a child of your SOAP/XML-RPC Request with code like:

import org.apache.commons.io.FileUtils;
import org.apache.commons.codec.binary.Base64;

String file = FileUtils.readFileToString(new File("/path/to/your/file.xml"),"UTF-8");
vars.put("file",new String(Base64.encodeBase64(file.getBytes("UTF-8"))));

It'll read contents of /path/to/your/file.xml file using UTF-8 charset and store result on "file" JMeter Variable.

Just put ${file} or ${__V(file)} into "SOAP/XML-RPC Data" text area. That's it.

See How to use BeanShell guide for more details on JMeter extension by scripting.

You can use View Results Tree listener to get full information on request/response.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thanks for the answer. But The file hast du be encoded with Base64? How can I do this? – SLo May 26 '14 at 11:14
  • I've updated Beanshell code snippet to encode file into Base64. – Dmitri T May 26 '14 at 11:28
  • This looks like the answer i'm looking for. Does it also works with pictures or binary data (PDF, compressed files, etc)? – SLo May 26 '14 at 13:07
  • The use case looks weird but the code above will read ANY file into string, encode it into Base64 and store it to `file` variable. – Dmitri T May 26 '14 at 13:13