HUE API JavaScript HTTP PUT请求返回" net :: ERR_EMPTY_RESPONSE"

时间:2016-03-23 22:35:30

标签: javascript angularjs ajax put philips-hue

  1. GET请求正常。

  2. 来自API调试工具的PUT请求正常工作。

  3. PUT和POST,无论使用何种数据或API网址,都会返回以下错误:

    示例:

    选项http://xxx.xxx.x.x/api/AuthorizedUsername/APIRequest/lights/light/1/state net :: ERR_EMPTY_RESPONSE

  4. 返回null响应。

    我的相关Angular JS代码:

    var bridgeIp = "http://xxx.xxx.x.x";
    var username = "authenticatedUsername";
    var lightData = {"on": true};
    
    $http.put(bridgeIp+"/api/"+username+"/lights/5/state", lightData)
    .then(function success(response) {
              console.log(response.data);
         }, function error(e){
              console.log(e);
         });
    

    我也尝试过使用JQuery的Ajax功能并收到同样的问题。

    我使用fiddler比较了请求,但是这导致了CORS错误。然后我将这些请求与Charles进行了比较。以下是这些结果:

    来自API调试工具:

    URL http://xxx.xxx.x.x/api/AuthorizedUser/lights/5/state
    Status  Complete
    Response Code   200 OK
    Protocol    HTTP/1.1
    SSL -
    Method  PUT
    Kept Alive  No
    Content-Type    application/json
    Client Address  /127.0.0.1
    Remote Address  xxx.xxx.x.x/xxx.xxx.x.x
    Timing  
    Request Start Time  3/23/16 18:24:17
    Request End Time    3/23/16 18:24:17
    Response Start Time 3/23/16 18:24:17
    Response End Time   3/23/16 18:24:17
    Duration    43 ms
    DNS 0 ms
    Connect 2 ms
    SSL Handshake   -
    Request 2 ms
    Response    1 ms
    Latency 37 ms
    Speed   20.46 KB/s
    Response Speed  879.88 KB/s
    Size    
    Request Header  427 bytes
    Response Header 421 bytes
    Request 12 bytes
    Response    41 bytes
    Total   901 bytes
    Request Compression -
    Response Compression    -
    

    从我的http请求到JavaScript:

    URL http://xxx.xxx.x.x/api/AuthorizedUser/lights/5/state
    Status  Failed
    Failure Remote server closed the connection before sending response header
    Response Code   -
    Protocol    HTTP/1.1
    SSL -
    Method  OPTIONS
    Kept Alive  No
    Content-Type    -
    Client Address  /127.0.0.1
    Remote Address  xxx.xxx.x.x/xxx.xxx.x.x
    Timing  
    Request Start Time  3/23/16 18:24:55
    Request End Time    3/23/16 18:24:55
    Response Start Time -
    Response End Time   3/23/16 18:24:55
    Duration    14 ms
    DNS 0 ms
    Connect 2 ms
    SSL Handshake   -
    Request 2 ms
    Response    -
    Latency -
    Speed   31.74 KB/s
    Response Speed  -
    Size    
    Request Header  455 bytes
    Response Header -
    Request -
    Response    -
    Total   455 bytes
    Request Compression -
    Response Compression    -
    

    感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

您的JavaScript输出显示Method as OPTIONS。 如果那是帖子顶部列出的OPTIONS,那看起来就错了,因为它说... APIRequest / lights / light / 1 / state, 但应该是...... APIRequest / / 1 /州