HTTP request block with POST give 500 error, how to solve this

536 views
Skip to first unread message

janwille...@gmail.com

unread,
Mar 24, 2017, 12:53:12 PM3/24/17
to Automate
Hi all,
As a new user I started using automate to build a flow to switch on automatically some lights in my home when I arrive after dark at my home.

The lights are switched on by using a HTTP POST request block using the following variable and input and output arguments:

Variable(s):
authorb64 = base64Encode("stretch:password", "")

Using the HTTP request block with settings
Request URL: http://192.168.10.105/core/appliances;id=switchid/relay
Request method: POST
Request content type: XML
Request content: "<relay>state>on</state></relay>"
basic authorization account: "stretch"
request headers: {"Host" as String":"192.168.10.105", "Connection":"Close", "Content-Type":"application/xml", "Authorization": "Basic " ++ authorb64}
certificate: Trust insecure certificates
redirect: empty
save response: to variable as text
output variables: status, response

gives errormessage in variable status: 500

I tried various options, but to no avail. How can I solve this?

A call with the Windows WinHttp.WinHttpRequest object works fine using the following code:
 PostAdres = Strcat("http://",StretchIP,"/core/appliances;id=",ApplianceID, "/relay")
 PostGegevens = StrCat("<relay><state>",SwitchStatus,"</state></relay>")
 oHTTP = ObjectCreate("WinHttp.WinHttpRequest.5.1")
 oHTTP.Open("POST", PostAdres, @False)
 oHTTP.SetRequestHeader("Host", StretchIP)
 oHTTP.SetRequestHeader("Connection", "Close")
 oHTTP.SetRequestHeader("Content-Type", "application/xml")
 oHTTP.SetRequestHeader("Authorization", StrCat("Basic ", AuthorBase64))
 oHTTP.Send(PostGegevens)
 PostResponse = oHTTP.ResponseText

Any suggestions?
 thanks for your help.
With regards, Jan Willem Teunisse

Henrik "The Developer" Lindqvist

unread,
Mar 25, 2017, 10:42:24 AM3/25/17
to Automate, janwille...@gmail.com
The request seems to be okay. None of the headers are required, use an Basic authorization account instead, the rest is set by default.

janwille...@gmail.com

unread,
Mar 25, 2017, 1:27:53 PM3/25/17
to Automate, janwille...@gmail.com
Dear Henrik,
Thanks for your swift reply. I changed the values in the HTTP block according to your suggestions, but now I'm stuck with a question about the format of the Basic authorization account.
It has the format of "username:password" like "stretch:password" or has it to be base064?
But in both cases the flow stops running in the http block.

if i use a wrong username I get the status 401, which is OK because it's according to the specification.

How do I have to set the Basic authorization account?

Regards, Jan Willem

Op zaterdag 25 maart 2017 15:42:24 UTC+1 schreef Henrik "The Developer" Lindqvist:

suranyi...@googlemail.com

unread,
Mar 26, 2017, 6:28:21 AM3/26/17
to Automate
Maybe too simple, but just to double check... is it maybe just the missing < in the request to open the <state> tag? Such XML issues would usually cause server to send 500, while when wrongly authenticated it does not go to that stage. At least it would explain the behaviour you have...

janwille...@gmail.com

unread,
Mar 26, 2017, 10:01:07 AM3/26/17
to Automate, suranyi...@googlemail.com
Good point, I made indeed a mistake in this field Request Content: I reversed the end tags </relay></state> instead of </state></relay>.

But after changing this, I still get the error. Just to make sure, is using username:password or do I have to use it in base-64? 

 

Op zondag 26 maart 2017 12:28:21 UTC+2 schreef suranyi...@googlemail.com:

Henrik "The Developer" Lindqvist

unread,
Mar 26, 2017, 10:08:41 AM3/26/17
to Automate, janwille...@gmail.com
Tap the "Basic authorization account" field to create an account, name it stretch or whatever, fill in username as stretch and password as password. No manual header dictionary or Base64 encoding needed

Henrik "The Developer" Lindqvist

unread,
Mar 26, 2017, 10:11:47 AM3/26/17
to Automate, suranyi...@googlemail.com, janwille...@gmail.com
Maybe the host only accept XML with a declaration, i.e. prepend to the content:
<?xml version="1.0"?>

janwille...@gmail.com

unread,
Mar 26, 2017, 12:48:32 PM3/26/17
to Automate, suranyi...@googlemail.com, janwille...@gmail.com
Thanks you all for your help suggestions. After a lot of expirementing I have now a setting that works.

It works by sing the HTTP request block with settings
Request URL: http://192.168.10.105/core/appliances;name=lampname/relay

Request method: POST
Request content type: XML
Request content: "<relay><state>on</state></relay>"
basic authorization account: empty
request headers: {"Authorization": "Basic " ++ authorb64}
certificate: empty

redirect: empty
save response: to variable as text
output variables: status, response

By the way the flow is used to switch on a ZigBee Plugwise adapter called a Circle.
Reply all
Reply to author
Forward
0 new messages