Forum Discussion

jarkko's avatar
jarkko
Occasional Contributor
12 years ago

[Resolved]HTTP Test Request vs inline files

Hello,

I am using soapUI Pro 4.6.0.

I am trying to do a test step that sends a straight forward HTTP POST to certain endpoint. This is easy enough if I copy-paste the desired request contents directly to the request editor (the free text area in "Request" tab).

however I am not currently able to "inline" this content from external file!

Sure enough I can create an "Attachment" out of this external file and then type the name of the attachment in request body. That way the contents of the file do get included in outgoing http request - but the resulting raw http request is completely different from the desired.

What I would like to send is:

--- request starts here ---

POST https://host.name.com/service HTTP/1.0
Content-Type: text/plain
Content-Length: 63
Host: host.name.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

THIS_IS_THE_TEXT_I_WANT_TO_INLINE
THERE_IS_LOTS_OF_TEXT_IN_HERE

--- request end here ---

What I get by using attachments is:

--- request starts here ---

POST https://host.name.com/service HTTP/1.0
Content-Type: text/plain; boundary="----=_Part_20_24250050.1382532907669"
MIME-Version: 1.0
Content-Length: 493
Host: host.name.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)


------=_Part_20_24250050.1382532907669
Content-Type: text/plain; charset=UTF8
Content-Transfer-Encoding: 8bit

inline.txt
------=_Part_20_24250050.1382532907669
Content-Type: text/plain; charset=UTF8; name=inline.txt
Content-Transfer-Encoding: quoted-printable
Content-ID: <inline.txt>
Content-Disposition: attachment; name="inline.txt"; filename="inline.txt"

=EF=BB=BFTHIS_IS_THE_TEXT_I_WANT_TO_INLINE
THERE_IS_LOTS_OF_TEXT_IN_HERE

------=_Part_20_24250050.1382532907669--

--- request end here ---

Reading the help pages I do get the impression, that inline files might be the feature I am looking for. But how do I inline the raw contents of an external file into body of the HTTP POST request without any encoding or additional headers?

I did also try typing something like "file:C:\inline.txt" in the request body, but that did not get replaved by files contents either. Maybe this works in SOAP requests only?

//Jarkko Siitonen
  • SiKing's avatar
    SiKing
    Community Expert
    I think you completely missed the point of attachments. Attachments are used to upload a file to the server API.
    What you are describing is reading the body of your message from a file. Read up on Data Source and Property expansion in SoapUI.
  • jarkko's avatar
    jarkko
    Occasional Contributor
    Yes, it is indeed quite likely, that I am trying to implement this the wrong way...

    I have been using data source loops before, but that is for reading the external files row by row, isn't it? Can I use data source to read the contents of entire file at once and then transfer all that to the body of one request?
  • Hi,

    A Groovy script step seems more natural. This line of code will read the entire contents of a file and save it to the context variable:

    context.setProperty("fileContents", new File("/tmp/test.txt").text)

    ... and then you can insert the file contents into the request XML with this expression

    ${= context.fileContents }

    Hope this helps!

    Manne
  • jarkko's avatar
    jarkko
    Occasional Contributor
    Thank you Manne!

    This did the trick I was trying to do.

    Sort of knew it must be possible to do somehow, but probably could not have figured this out by myself!

    //Jarkko