Forum Discussion

richie's avatar
richie
Community Hero
7 years ago
Solved

POSTING plain text via a property to a REST Service

Hi,

 

I feel a bit of a dunce posting this message,  cos it should be straight forward - but it;s not working!

 

I have a REST resource, method, request setup which I intend to POST to, but the content of the request doesn't have any XML its sourced from a flat text file in the following format:

CustRefID|title|firstname|lastname|addressline1|addressline2|addressline3|postcode
ID0000001|MR|RICH|JONES|5 WHATEVER WAY|HODGE HILL|BIRMINGHAM|B36 9LB
Rows=1

 

I have a property created on the Testsuite (and I am sourcing the property '${#TestSuite#fileContents}') on the 'Request' form that contains the contents of the above file but when I tried submitting the POST request, the 'Form' tab indicates that I get an apache error saying 'unexpected element: CDATA'

 

I thought the problem was something to do with the Media Type: so I've set it to  'text/xml' (on the 'Request' tab) but it's still not working.  I changed the type to various other options but none of them worked.  I've had a look on this forum and I did find something on attachments (that I also couldnt get to work) but nothing that really helped.

 

My Web Services Testing with SoapUI book is also very good, but doesn't answer my question.

 

 

Any help advice/guidance anyone can provide would be great!

 

I've attached a screenshot and my project file if anyone wants to have a look

 

Many thanks!

 

richie

  • Hello Richie, 

     

    Thanks for posting in the SmartBear Community Forum.

     

    The error you are receiving is due to the message body not being in XML format.

     

    To solve the immediate error, you should modify the body to:

    <file_contents>${#TestSuite#fileContents}</file_contents>

     

    As a side note, I would recommend sending the data as an attachment since it is easier to manage  if the data gets larger (if that is the case). https://support.smartbear.com/readyapi/docs/projects/requests/attachment/rest.html

2 Replies

  • StevenColon's avatar
    StevenColon
    SmartBear Alumni (Retired)

    Hello Richie, 

     

    Thanks for posting in the SmartBear Community Forum.

     

    The error you are receiving is due to the message body not being in XML format.

     

    To solve the immediate error, you should modify the body to:

    <file_contents>${#TestSuite#fileContents}</file_contents>

     

    As a side note, I would recommend sending the data as an attachment since it is easier to manage  if the data gets larger (if that is the case). https://support.smartbear.com/readyapi/docs/projects/requests/attachment/rest.html

    • richie's avatar
      richie
      Community Hero

      Hi,

       

      Does it make any difference that the message body is contained with XML tags?  The developer I'm dealing with told me that only the message content should be posted.

       

      If I changed the MediaType to text/plain - would this allow me to remove the containing <file_contents> tags?

       

      You did mention using the attachment function - I was reading about this before - but I was unsure if I use this attachment function that alters the request in some way - in regards to the request hitting and being processed by the resource - does it have any impact?  I haven't been able to get a specific answer on this from my reading.

       

      Many thanks for all your help!

       

      richie