using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using MiHome.Net.Middleware;
using MiHome.Net.Service;
var hostBuilder = Host.CreateDefaultBuilder();
//添加小米米家的驱动服务,需要小米账号和密码
hostBuilder.ConfigureServices(it => it.AddMiHomeDriver(x =>
{
x.UserName = "xxx";
x.Password = "xxx";
}));
var host = hostBuilder.Build();
var miHomeDriver = host.Services.GetService<IMiHomeDriver>();
//列出家庭里所有的智能家居设备
var deviceList = await miHomeDriver?.Cloud?.GetDeviceListAsync(); // <---- 这里出错
Console.WriteLine(deviceList);
控制台信息:
info: System.Net.Http.HttpClient.MiHome.Net.FeignService.IXiaoMiLoginService.LogicalHandler[100]
Start processing HTTP request GET https://account.xiaomi.com/pass/serviceLogin?sid=xiaomiio&_json=true
info: System.Net.Http.HttpClient.MiHome.Net.FeignService.IXiaoMiLoginService.ClientHandler[100]
Sending HTTP request GET https://account.xiaomi.com/pass/serviceLogin?sid=xiaomiio&_json=true
info: System.Net.Http.HttpClient.MiHome.Net.FeignService.IXiaoMiLoginService.ClientHandler[101]
Received HTTP response headers after 325.6286ms - 200
info: System.Net.Http.HttpClient.MiHome.Net.FeignService.IXiaoMiLoginService.LogicalHandler[101]
End processing HTTP request after 354.8538ms - 200
info: System.Net.Http.HttpClient.MiHome.Net.FeignService.IXiaoMiLoginService.LogicalHandler[100]
Start processing HTTP request POST https://account.xiaomi.com/pass/serviceLoginAuth2?_json=true
info: System.Net.Http.HttpClient.MiHome.Net.FeignService.IXiaoMiLoginService.ClientHandler[100]
Sending HTTP request POST https://account.xiaomi.com/pass/serviceLoginAuth2?_json=true
info: System.Net.Http.HttpClient.MiHome.Net.FeignService.IXiaoMiLoginService.ClientHandler[101]
Received HTTP response headers after 132.9929ms - 200
info: System.Net.Http.HttpClient.MiHome.Net.FeignService.IXiaoMiLoginService.LogicalHandler[101]
End processing HTTP request after 138.56ms - 200
Unhandled exception. System.UriFormatException: Invalid URI: The hostname could not be parsed.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
at System.Uri..ctor(String uriString)
at SummerBoot.Feign.DefaultFeignUnitOfWork.GetCookies(String url)
at SummerBoot.Feign.FeignAspectSupport.ProcessCookie(RequestTemplate requestTemplate)
at SummerBoot.Feign.FeignAspectSupport.BaseExecuteAsync[T](MethodInfo method, Object[] args, IServiceProvider serviceProvider)
at SummerBoot.Feign.HttpService.ExecuteAsync[T](List`1 originArgs, MethodInfo method, IServiceProvider serviceProvider)
at MiHome.Net.Service.MIotCloud.GetInternalLoginInfoAsync()
at MiHome.Net.Service.MIotCloud.GetLoginInfoAsync()
at MiHome.Net.Service.MIotCloud.BeginControlDeviceCookieAsync()
at MiHome.Net.Service.MIotCloud.GetDeviceListAsync()
at Program.<Main>$(String[] args) in G:\code\WpfApp1\MiHomeTest\Program.cs:line 16
at Program.<Main>(String[] args)
``
控制台信息: