【问题标题】:How to get an http json response from the philips hue bridge after a put放置后如何从飞利浦 Hue 桥获得 http json 响应
【发布时间】:2016-02-21 19:56:54
【问题描述】:

在完成 PUT 请求后,我正在尝试从 Philips Hue 获取 json 响应。飞利浦 Hue 有一个内置的 Web 服务器命令行,当我使用 Hue Web 界面发送一个基本的 json 消息,如“{“on”:True}”时,我收到一个 json 响应,告诉我请求成功。消息如下所示:

"[
    {
        "success": {
            "/lights/1/state/on": true
        }
    }
]"

现在,当我通过下面的设置向色调发送命令时,我总是得到一个 TRUE .IsSuccessStatusCode(我假设因为色调收到了消息?)即使我发送了一些应该导致错误。例子;我可以使用 json {"on":Cause an error} 并且仍然得到 TRUE。

所以我试图弄清楚在我发送 PUT 后如何从色调中获取上述 json 响应。下面是我正在使用的代码。

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;


    async static void setLight()
    {
        HttpClient client = new HttpClient();

        HttpRequestMessage request = new HttpRequestMessage();

        String myJson = "{\"on\":false}";

        var content = new StringContent(myJson, Encoding.UTF8, "application/json");

        HttpResponseMessage returnStatement = await client.PutAsync("http://192.168.1.3/api/139f12ce32a30c473368dbe25f6586b/lights/1/state", content);

        Console.WriteLine(returnStatement.IsSuccessStatusCode);

    }

【问题讨论】:

    标签: c# json http philips-hue


    【解决方案1】:
     Console.WriteLine("Return Statment:" + await returnStatement.Content.ReadAsStringAsync());
    

    这将返回我正在寻找的 json 色调响应。我只是不断地获取基本的 http 信息,直到我将 await 关键字放在它前面。大声喊出 Q42.hueApi,我在您的代码中达到了顶峰,这对您有很大帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-18
      • 2015-02-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多