Forum Discussion

pkinoc's avatar
pkinoc
Occasional Contributor
12 years ago

[Resolved] Multipart question

I have some Java code to do loadtesting of a REST service and I'd like to convert some of it to Soapui for functional testing. The request includes sending some multipart data as a byte array once the connection is open but I'm not sure where to do this in soapui.

The snippet of code below sends the request using Java by writing it to the output stream.


connection = (HttpURLConnection) serverAddress.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setAllowUserInteraction(true);
connection.setDoInput(true);
connection.connect();


wr = connection.getOutputStream();
byte[] byteData = TestMultipart.getMultipartContent();
wr.write(byteData);
wr.flush();


Now, I converted the Java code to Groovy to create the byte array. The question is, where do I add this to the request?

Thanks,
Peter

3 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi Peter,

    Do as follows:

    1) save the binary content you want to send to a file
    2) create an HTTP Request Step in a TestCase with POST and the correct URL
    3) add the file as an attachment to the request (in the attachments tab at the bottom left of the request window)
    4) make sure that the "Media Type" field in the request window has the same value as the "Content type" column for your attachment (for example application/octet-stream)
    5) submit the request!

    This should result in soapUI sending the attached file as the content of the request.

    Does this work ok?

    regards,

    /Ole
    SmartBear Software
  • pkinoc's avatar
    pkinoc
    Occasional Contributor
    Yes, it does!!

    Next time you're in southern California I will buy u a beer!

    Thanks for your help!

    Peter