Search code examples
web-servicesjmetersendfile

JMETER: Sending Files with Webservice Request


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...


Solution

  • 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.