Page 1 of 1

Updating text area field with string containing line breaks

PostPosted: Wed Mar 16, 2022 9:47 pm
by Joe.Thorpe
Hi,

What's the right way to insert a line break into a text area field?

My use case is I'm trying to update the CourierDetails field on SO_History, using the following HTTP request:

POST {{baseUrl}}/SalesOrders/c844592daa4a4d1ba8d2?DeliveryAddressCourierDetails=test1\r\ntest2%5Cr%5Cntest3\ntest4
The Jiwa client shows "test1\r\ntest2\r\ntest3\ntest4". I know the field can have multiple lines as you can hit Ctrl+Enter in the client to enter a newline.
Looking at the raw output, it appears to be double escaping the escape characters (the \\r\\nd bit at the end was from me inserting a newline through the client).
"test1\\\\r\\\\ntest2\\\\r\\\\ntest3\\\\ntest4\\r\\nd\"

I've had a look through the forum and Servicestack docs, I can't see an obvious way of doing it.

Cheers!

Re: Updating text area field with string containing line bre  Topic is solved

PostPosted: Thu Mar 17, 2022 1:38 am
by Mike.Sheen
I tried this with postman - like so:

Postman.png
Postman.png (26.29 KiB) Viewed 13545 times


This resulted in the field having a line break:

Jiwa.png
Jiwa.png (32.02 KiB) Viewed 13545 times


The Fiddler capture of the request reveals Postman translated that to the typical 0D 0A pair:

Fiddler.png


What you've shown me is you're using URL parameters - so perhaps instead of your \n\r just put %0D%0A - but ideally you should dispense with the url parameters for everything except GET requests - for POST and PATCH operations set the body to be the json like shown in my Postman screenshot.

Re: Updating text area field with string containing line bre

PostPosted: Thu Mar 17, 2022 12:19 pm
by Joe.Thorpe
Thanks Mike, that worked perfectly.

I was using url params because the Postman collection from the Jiwa OpenAPI defaults to Content-Type application/x-www-form-urlencoded.

Cheers!

Re: Updating text area field with string containing line bre

PostPosted: Thu Mar 17, 2022 12:26 pm
by Mike.Sheen
Joe.Thorpe wrote:I was using url params because the Postman collection from the Jiwa OpenAPI defaults to Content-Type application/x-www-form-urlencoded.


That might be a configuration - because when I examine the Postman meta data I see the content headers designated as application/json:

postman meta.png


Do you see the same when visiting the /postman route, - does yours show "headers":"Accept: application/json"?

Re: Updating text area field with string containing line bre

PostPosted: Thu Mar 17, 2022 12:31 pm
by Joe.Thorpe
Ah yeah it's application/json there, so i did something wrong when I imported the collection. All good, i'll figure it out.