Getting an error "Unable to parse HTTP request"

Hello guys,

I’m trying to parse my URL with wildcards. The problem appears when I try to parse long strings with a wildcard. For example, my URL looks like this:

http://testapi.com/v1/cards/%s/reissue?DesignId=%s&Comment=%s

and this is my code:

get_object.setRestUrl(String.format(url, card_id, design_id, comment))

When comment = "Something" it works, but when comment = "Something something" , it goes on an error and says that it is “Unable to parse HTTP request”.

How is it possible to make suitable my code with long strings with wildcards? I know that when typing long string it gives URL that looks like this:

http://testapi.com/v1/cards/1/Block?reasonId=1&comment=Something%20like%20that%20example

As you wrote - a space must be escaped in URL (using Hex code %20)

get_object.setRestUrl(String.format(url, card_id, design_id, comment.replace(" ", "%20")))
1 Like

Yes, but will it work when string will be short ?

It works for all strings with a space - String.replace method is self-descriptive. :slight_smile: HTTP does not accept spaces at all - doesn’t matter if string length is 10 or 100.

Oh, I mean that will it work even when I will have string without space ?

Yes - when no space is present, nothing is replaced.

1 Like

Well thank you ! I tried and it works perfectly !!!