HTTPClient POST Request and the timeout option

I am working on a plugin that uses the HTTPClient and a POST request. I am trying to lower the timeout to 1000ms so it ‘fails’ quickly and I can move on in the code to a different method. (The POST will timeout if the device is powered off.)

If I let it run long enough, it does timeout after around 20 seconds. However, if I adjust the timeout, it does not seem to make a difference:

var http = new HTTPClient();
var httpConfig = { timeout: 1000 };
var resp = http.post("http://<Address>", httpConfig);

Of note, I can seem to be able to adjust the timeout for a GET request.

You know…it’s the 5th time you read the documentation it makes sense.

I realized I was missing the ‘data’ parameter.

Now it works if I do:

var http = new HTTPClient();
var httpConfig = { timeout: 1000 };
var resp = http.post("http://<Address>", "", httpConfig);
1 Like