You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu Core无curl/wget时如何发送HTTPS/HTTP请求?

在Ubuntu Core中发送HTTPS/HTTP请求的可行方案

在Ubuntu Core里发HTTPS/HTTP请求确实有点棘手——默认没预装curl、wget这类常用工具,不过针对你要更新DtDns的需求,我整理了两种实用思路,其中你自己摸索的打包经典模式Snap包的方案非常靠谱,我来给你细化完善下:

方案一:用Python标准库轻量实现(无需额外工具)

如果你的Ubuntu Core系统自带Python3(多数版本默认会预装),完全可以用内置的urllib库直接发起请求,不用额外安装任何工具。写个简单的脚本就能搞定:

import urllib.request

# 替换成你的DtDns完整请求链接
DTDNS_URL = "https://www.dtdns.com/api/autodns.cfm?<你的参数>"

try:
    # 发起请求并获取响应
    response = urllib.request.urlopen(DTDNS_URL)
    print("更新结果:", response.read().decode("utf-8"))
except Exception as e:
    print("请求失败:", str(e))

把脚本保存成update_dtdns.py,直接运行python3 update_dtdns.py就能触发DtDns更新,适合轻量、临时的场景。

方案二:打包经典模式Snap包(长期复用方案)

如果依赖curl的功能,或者希望这个更新工具能长期稳定复用,打包成经典模式的Snap包是绝佳选择。下面是完善后的配置和步骤:

1. 核心配置文件snap.yaml

name: dtdns-updater
version: '1.0'
summary: DtDns域名更新工具(内置curl)
description: |
  打包curl和自定义更新脚本,解决Ubuntu Core无网络工具的问题,用于自动更新DtDns解析。

base: core22
confinement: classic  # 经典模式确保curl能正常访问网络和系统资源

apps:
  update-dtdns:
    command: bin/update_dtdns.sh

parts:
  curl:
    plugin: nil
    override-build: |
      apt-get update
      apt-get install -y curl
      cp /usr/bin/curl $SNAPCRAFT_PART_INSTALL/bin/
  scripts:
    plugin: dump
    source: ./scripts/
    organize:
      update_dtdns.sh: bin/update_dtdns.sh

2. 配套的bash更新脚本(scripts/update_dtdns.sh)

#!/bin/bash
# 替换成你的完整DtDns请求链接
curl "https://www.dtdns.com/api/autodns.cfm?<你的完整参数>"

3. 打包与安装步骤

  • 先在开发环境安装snapcraft:sudo snap install snapcraft --classic
  • 按如下目录结构整理文件:
    dtdns-updater/
    ├── snap/
    │   └── snap.yaml
    └── scripts/
        └── update_dtdns.sh
    
  • 给脚本加执行权限:chmod +x scripts/update_dtdns.sh
  • 进入项目目录,运行snapcraft pack生成Snap包
  • 在Ubuntu Core设备上安装:sudo snap install dtdns-updater_1.0_amd64.snap --dangerous
  • 之后直接执行update-dtdns就能触发DtDns更新

这种方案把依赖和脚本打包成独立的Snap,不受系统环境限制,还能通过Snap的机制管理版本和权限,非常适合长期使用。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 08:49:13