I need to send a PUT request with a payload to an API (Philips Hue Bridge), but I have some limitations in javascript.
I can only use:
XMLHttpRequest methods:
open(method, url [, async = true [, username = null [, password = null]]])
Sets the request method, request URL, and synchronous flag.
Supported request method : GET, POST
send(data = null)
Initiates the request. The optional 'data' argument allows only UTF-8 encoded string type. The argument is ignored if request method is GET.
abort()
Cancels any network activity.
This limitation comes from the Tizen Wearable Web Widget Specification
Philips Hue Bridge API expects:
URL: http://hostname/api/username/lights/lightKey/state
Method: PUT
Payload example: {"on": true}
What I tried:
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://hostname/api/username/lights/lightLey/state?on=true');
xhr.send();
Response: 400 (Bad request)
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://hostname/api/username/lights/lightLey/state?on=true');
xhr.send();
Response: 400 (Bad request)
Also tried GET
and POST
with following URL endings:
../state?{on=true}
../state?{on:true}
../state?{"on"=true}
../state?{"on":true}
Response: 400 (Bad request)
Again, I cannot use any additional libraries or commands besides the XMLHttpRequest methods mentioned above.
How can I solve this?