OH2: sendHttpPostRequest --> NullPointerException

Hi,

I am getting NullPointerException in OH2 by using:
sendHttpPostRequest(uri, "HTTP.CONTENT_TYPE_JSON", string)

as in OH1 it is working fine, what needs to be changed in the request?
It would be great if someonce could provide me some examples of “sendHttpPostRequest” from OH2.

thanx, Martin

Try explicitly including quotes around your string. So, if your string is say {"a" : "b"}, you can try '{"a" : "b"}'.

I’m also getting a NullPointerException when trying to do a sendHttpPostRequest with OpenHab2. With OH1 the rule worked without any issues. So, I’m wondering what could be changed?

UPDATE: I got it working by changing the URL top only have one argument passing over and also using the post data function with timeout value:

request = 'http://server/middleware.php/sensor.json?operation=add&value=' + AussenTemperatur.state.toString
sendHttpPostRequest(request)

to:

request = 'http://server/middleware.php/sensor.json?value=' + AussenTemperatur.state.toString
sendHttpPostRequest(request, "application/json", "")

Regards,
Michel

I would claim that the second parameter needs to be without quotes as you are referencing the constant HTTP.CONTENT_TYPE_JSON. Alternatively, you can directly use the string "application/json".

Could you enter a bug at Issues · eclipse-archived/smarthome · GitHub, please?

Created bug [#2540](https://github.com/eclipse/smarthome/issues/2540)

I am still experiencing this issue with the latest snapshot.

Sorry for reviving this tread,
I am getting :
] [smarthome.event.ItemStateChangedEvent] - Garasje changed from OFF to ON
15:01:14.918 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule ‘Garasjedorr’: Illegal character in query at index 98: http://192.168.2.242:2015/cgi-bin/CGIproxy.fcgi?cmd=ptzGotoPresetPoint&name=2&usr=Admin&pwd=XXXX

Whet trying this in rule
sendHttpPostRequest ('http://192.168.2.242:2015/cgi-bin/CGIproxy.fcgi?cmd=ptzGotoPresetPoint&name=2&usr=Admin&pwd=XXXX