HTTP binding URL formatting issue - Error 400

Hi,

I have trouble to get the URL formatted correctly for an API access. I’m using the HTTP binding on my OH3.3 installation. I have a working curl example that I want to port to the HTTP binding for JSON processing. The URL contains parameters which contain a “+” which must be escaped to “%2B” for curl to work. The HTTP binding does not allow me to use the escaped character like that while using the “+” character leads to an Error 400:

https://api.server/data/60?tz=UTC+01:00 vs. https://api.server/data/60?tz=UTC%2B01:00

BaseURL is https://api.server/data/ and 60?tz=UTC+01:00 is the stateExtension in the channel. When using “%2B” the HTTP binding UI is complaining.

openhab.log shows:

2023-01-18 09:37:40.578 [WARN ] [p.internal.http.HttpResponseListener] - Requesting 'https://api.server/data/60?tz=UTC+01:00' (method='GET', content='null') failed: 400 Bad Request

How to work around this issue?

Isn’t that what the “Escaped URL” toggle on the Channel is for? Use “+” in your properties and toggle that on and the binding will replace it with “%2B” for you.

Hi Rich,

no, that does not change anything. The URL still contains the “+” when “Escaped URL” is enabled and the Error 400 is returned.

When replacing the “+” with “%2B” in the stateExtension while keeping “Escaped URL” on, I get the complain again:

2023-01-18 20:33:07.429 [WARN ] [ttp.internal.http.RefreshingUrlCache] - Creating request for 'https://api.server/data/60?tz=UTC%2B01:00' failed: Format specifier '%2B'

Any idea?

I wouldn’t expect it to work with Escaped URL enabled and the URL String already escaped. Beyond that I’ve no ideas.

Hi Rich,

ok, I solved the formatting issue on the “+” by good old RTFM:

In certain scenarios you may need to manually escape your URL, for example if you need to include an escaped = (%3D) in this scenario include %%3D in the URL to preserve the % during formatting, and set the parameter escapedUrl to true on the channel.

Yet I’m still getting Error 400. So there is another(?) issue. Is there a way to get the full call with the header?

… ok, I solved it. I had to turn off authentication which is not needed. EscapedURL is still required, the “+” does not get escaped automatically by the formatter.

It is as always - as soon as one makes it right, it works :stuck_out_tongue_winking_eye:

Glad you got it working. To answer this question, you can put the binding into trace level logging and it will show you the full URL and headers and data being sent.