You need to enable JavaScript to run this app. Windows PowerShell中curl调用Digital Loggers脚本失败求助
优惠活动
大模型
产品
解决方案
定价
更多

Windows PowerShell中curl调用Digital Loggers脚本失败求助

问题解决思路

一、PowerShell中curl调用失败的解决方法

PowerShell里的curl是Invoke-WebRequest的别名,它对包含用户名密码的URL解析逻辑和浏览器不同,这就是报错的核心原因。可以用以下两种方式解决:

  1. 调用真实的curl.exe工具(Windows 10/11默认已预装)
    直接使用系统自带的原生curl,避开PowerShell的别名限制:
curl.exe "http://admin:MyPassword@MyIp:MyPort/script?run001=run"
  1. 用PowerShell内置命令单独传入凭证
    如果坚持用PowerShell原生命令,需要拆分用户名密码为凭证参数传入:
# 交互式输入密码(安全推荐)
$cred = Get-Credential -UserName "admin" -Message "输入Digital Loggers密码"
Invoke-WebRequest -Uri "http://MyIp:MyPort/script?run001=run" -Credential $cred

如果需要非交互式执行(不推荐明文写密码):

$user = "admin"
$pass = ConvertTo-SecureString "MyPassword" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($user, $pass)
Invoke-WebRequest -Uri "http://MyIp:MyPort/script?run001=run" -Credential $cred

二、Home Assistant控制Digital Loggers设备的方案

自动发现失败不用纠结,直接用RESTful命令实现控制,步骤如下:

  1. 在Home Assistant的configuration.yaml中添加REST命令配置:
rest_command:
  digital_loggers_switch:
    url: "http://admin:MyPassword@MyIp:MyPort/script?run001=run"
    verify_ssl: false

为了安全,也可以把密码存到secrets.yaml中:

# secrets.yaml
dl_device_password: MyPassword

# configuration.yaml
rest_command:
  digital_loggers_switch:
    url: "http://admin:!secret dl_device_password@MyIp:MyPort/script?run001=run"
    verify_ssl: false
  1. 重启Home Assistant后,就能在自动化、脚本或开发者工具里调用rest_command.digital_loggers_switch服务来控制插座。

另外检查下:Home Assistant和Digital Loggers设备是否在同一局域网网段,设备防火墙是否阻止了HA的访问,确保端口处于开放状态。

内容的提问来源于stack exchange,提问作者FormalHitman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 17:22:37