411 Error using httpClient

Hy, I am trying to retrieve XML data from a REST API. I am trying this via the script console.

However, I am always getting a 411.

The API documents tell me to use a POST and to pass in the username and password via parameters.

For ignition I use the following:

client = system.net.httpClient(bypass_cert_validation = True)
access_response = client.post(url="https://xxxx.svc/?username=xxxx&password=xxxx")

The response I get is:

<Response@247370237 'https://xxxx.svc/?username=xxxx&password=xxxx' [411]>

Since the 411 means the server is looking for a content-length, I have also tried to add data="" to the httpClient method just to give it data.

I have also tried to set Content-Length to 0 in the headers but get a java error saying I can't do that.

I have been successful using POSTMAN to post to this server.

Any ideas?



Never mind. I changed data="" to data="0" and it works.



1 Like

This is a bit of an issue with the implementation of Java 11's HttpClient.

It restricts the Content-Length header from being set manually, and automatically includes it, but only if there is a non-empty body. This is technically compliant behavior, though I don't think it's in line with recommendations.

Thanks for the quick response! I can live with adding a short piece of data.


Yes, easy workaround, as long as your API doesn't balk at it.