1
votes

I have the newly released Philips Hue bridge and I'm trying to control it from my browser by sending JSON requests to it. I am using a third party 'helper' api just to make things a little easier - but it's irrelevant which one because underneath it is just sending a regular PUT request. I am just using Chrome to run the JS locally (on a local webserver).

PUT http://192.168.1.86/api/2e51aa2362f1a416d8eab4816b669eb/lights/16/state

{ on: true }

The problem is I am receiving back the following CORS error:

XMLHttpRequest cannot load http://192.168.1.86/api. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.com' is therefore not allowed access.

This makes perfect sense - and I understan what's doing on - after all I am trying to make a PUT request to a remote server and as a result my browser is prohibiting me. However I obviously can't change the code on the hub.

Is there any solution to this? I see that a while ago that Philips needed to do something similar on their own website to allow for cross domain access.

I can find very little information about this out there - and I'm not sure if Philips recently changed something. The fact that third party JS APIS don't even mention this makes me believe that Philips may have changed something (I found a third party webapp which has this same problem).

Edit:

These are the headers coming back:

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: text/html
Content-Length: 0
2

2 Answers

4
votes

It turns out Fiddler (Windows HTTP debugging proxy) was conflicting somehow with my CORS request - which doesn't make any sense but for now I just closed Fiddler and it is working fine and able to give a PUT request.

I had 'Stream' enabled but that didn't make a difference.

1
votes

The Philips hue bridge sends the "Access-Control-Allow-Origin:*" header so it should just work. As far as I know it always did this.

I just checked with a copy of the "clip.html" file (found on the bridge) which I placed on a different webserver and it works fine.

Are you sure you are using the correct IP address (e.g. does a GET to the bridge work?)