gpt4 book ai didi

C# Hue Bridge PUT 发送 OK 响应。无 API 响应

转载 作者:太空宇宙 更新时间:2023-11-03 12:10:43 31 4
gpt4 key购买 nike

<分区>

所以我到处搜索,甚至在 neigh dead 官方论坛上问过。我在这里搜索过,但回复已有多年历史,并且经常包含无效链接。

我只是想打开家里的灯。我已经通过调试工具进行了授权,并获得了我的“用户名”,然后将其硬编码到这个应用程序中。同样,这只是我在测试它。我什至将一个功能性 url ( http://192.168.0.100/api/RjplsYoXQvdTl11DOVIo92SKNB7vYRfwZvqCzvDK/lights/2/) 复制到其他浏览器和设备中,以确保我不必在不同设备上通过重新授权进行处理。是的,我也知道我正在从同步转向异步,但除非那是问题,否则我不担心将程序卡在那里。我只是想在 API 中切换一些东西 :)

所以问题是响应只是一个通用的 HTTP 200 OK 响应,而不是预期的 API 响应。

我得到:

StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnection+HttpConnectionResponseContent, Headers:
{
Server: nginx
Date: Sun, 23 Sep 2018 18:37:44 GMT
Connection: close
Cache-Control: no-store, must-revalidate, no-cache, post-check=0, pre-check=0
Pragma: no-cache
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
Expires: Mon, 01 Aug 2011 09:00:00 GMT
}

当我期待

   {"success":{"/lights/1/state/on":false}},

这是代码。有人可以对此有所了解吗?谢谢

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json;


namespace ConsoleApp1
{

class Program
{
static HttpClient client = new HttpClient();
static HttpResponseMessage response = new HttpResponseMessage();

public class StateO
{
public bool On { get; set; }
public int Bri { get; set; }
}
public class Light
{
public string Name { get; set; }
public StateO State { get; set; }
public Light()
{
State = new StateO();
}
}

static void Main(string[] args)
{
client.BaseAddress = new Uri("http://192.168.0.100/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
UpdateProductAsync().GetAwaiter().GetResult();

}
public static async Task<Light> UpdateProductAsync()
{
Light light = new Light();
light.State.On = false;
string json = JsonConvert.SerializeObject(light);

response = await client.PutAsJsonAsync(
$"api/RjplsYoXQvdTl11DOVIo92SKNB7vYRfwZvqCzvDK/lights/2/", json);
Console.WriteLine("potato: " + response.ToString());
response.EnsureSuccessStatusCode();
// light = await response.Content.ReadAsAsync<Light>();
return light;
}
}

}

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com