Mir:ror / RFID ...
#11
Raoul - 

we've reach an impasse with trying to get Applescript to send POST requests to our Home Automation ... 

GET request works OK, but not POST ... 

the problem seems to be there's a bug in Applescript ... (!)

so ... was hoping you might see a work-around ... ?? !!

Chris

details :

the requests in Postman, look like this:


curl --location --request GET 'http://nnn.nn.nn.nn:nnn/api/v1/Objects/2213' --header 'Authorization: Basic nnnnnnnnnnnnnnn'

curl --location --request POST 'http://nnn.nn.nn.nn:nnn/api/v1/Objects/2213?6=1' --header 'Authorization: Basic nnnnnnnnnnnnnnn'

and both work ... 

and in Applescript, they look like this :

do shell script "curl --location --request GET 'http://nnn.nn.nn.nn:nnn/api/v1/Objects/2213' --header 'Authorization: Basic nnnnnnnnnnnnnnn'"

do shell script "curl --location --request POST 'http://nnn.nn.nn.nn:nnn/api/v1/Objects/2213?6=1' --header 'Authorization: Basic nnnnnnnnnnnnnnn'"

and only the GET works ... 

of course, enclosing a string in single quotes - 'abcdef&/whatever' - is a way of ensuring it's passed-on verbatum, without triggering any response from the application that's handling it / sending it on ... 

but there seems to be a bug in Applescript ... 

Googling a lot, brings up comments pointing to it mishandling things within single quotes within double quotes - as in "abcd 'nhygf' ajyhe" ... 

and comments that say we should use quoted form of in strings containing spaces & other special characters (like & and ?) ... 

eg: quoted form of (gjsfhjfsafjsdfagh?&jsj) ... 

there's also mention of escaping - as in using the \ character to avoid misinterpretation of strings ... as in \" and \\ ... 

some of these comments go back almost twenty years ... 

I found no examples to illustrate any of their use in our situation, but have experimented with what I could imagine ... without success ... my understanding of all this is very limited, though ... 

bottom - line ... Applescript's problem seems to be with the ? character in the POST request, even though it's contained within a string that is enclosed within single quotes ... 

so ...question is - is there an alternative to it, somehow... ???


PS: did have a look at using Wireshark & Fiddler - but we're running OSX 10.11.6, with which they say they are not compatible ...

references :

https://curl.se/docs/

https://macscripter.net/viewtopic.php?id=22970

https://stackoverflow.com/questions/...in-applescript
Répondre
#12
to answer my own question, the POST request fails because it waits on data that never arrives ... 

the fix is to include null data in the form of -d'' (where the '' is two single quotes) ... 

as follows :

do shell script "curl --location --request GET 'http://nnn.nn.nn.nn:nnn/api/v1/Objects/2213' --header 'Authorization: Basic nnnnnnnnnnnnnnn'"

do shell script "curl --location --request POST 'http://nnn.nn.nn.nn:nnn/api/v1/Objects/2213?6=1' -d'' --header 'Authorization: Basic nnnnnnnnnnnnnnn'"

the significance of this is that we can now use RFID tags (both Nano:ztag and Ztamps) to command things about our house, via our Idratek home automation system ... 
Répondre


Atteindre :


Utilisateur(s) parcourant ce sujet : 1 visiteur(s)