Thanks so much; however, I'm still having trouble getting the lights to respond. I had to alter your example somewhat, because Racket was complaining about an "in-string: contract violation". The following seems to work:
(http-sendrecv
"192.168.1.95" "/api/<username>/lights/1/state"
#:method 'PUT
#:data
(alist->form-urlencoded
(list (cons 'bri "1")
(cons 'ct "500")))
#:headers
'("Content-Type: application/x-www-form-urlencoded"))
However, instead of affecting the light, I just get the following on the REPL:
#"HTTP/1.1 200 OK"
'(#"Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
#"Pragma: no-cache"
#"Expires: Mon, 1 Aug 2011 09:00:00 GMT"
#"Connection: close"
#"Access-Control-Max-Age: 3600"
#"Access-Control-Allow-Origin: *"
#"Access-Control-Allow-Credentials: true"
#"Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE, HEAD"
#"Access-Control-Allow-Headers: Content-Type"
#"Content-type: application/json")
#<input-port:pipe>
I've also tried sending the message using:
#:data
(form-urlencoded-encode "\"bri\": 1")
and changing the #:headers to '("Content-Type: application/json")
Any thoughts?
My best,
Bruce
On Wednesday, June 17, 2015 at 11:35:32 AM UTC-4, Alexis King wrote:
> You probably want to use the net/http-client library, specifically the http-sendrecv function. I’m not 100% sure, but I’d guess that the equivalent Racket code for your curl command would look something like this.
>
> (require net/http-client
> net/uri-codec)
>
> (http-sendrecv
> "192.168.1.20" "/api/<username>/lights/8/state"
> #:method 'PUT
> #:data
> (alist->form-urlencoded
> '((on #t)
> (bri 170)
> (ct 500)))
> #:headers
> '("Content-Type: application/x-www-form-urlencoded"))
>
> See
http://docs.racket-lang.org/net/http-client.html#%28def._%28%28lib._net%2Fhttp-client..rkt%29._http-sendrecv%29%29
>