首页 > 解决方案 > 通过 https 访问比特币节点

问题描述

我通过 https 链接拥有自己的比特币测试网节点,当我想通过 curl 对其进行 ping 操作时

curl https://link_to node/ 我有这样的回应

JSONRPC server handles only POST requests 

所以这意味着我可以连接到节点并向它发送请求,所以我想通过 nodejs 和比特币核心连接到它。我想初始化比特币对象

const bitcoin = require('bitcoin-core');
    let client = new bitcoin({
        network: 'testnet', 
        username: 'user', 
        password: 'password', 
        host: 'https://link_to_node/',
        timeout: 30000,
        port: 443
    });

    client.upTime((err, res) => {console.log(err, ' and ', res);})</i>

在这里,我连接到节点并发送有关其正常运行时间的请求并收到类似的响应

错误:getaddrinfo ENOTFOUND https:80 at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26) 错误:'ENOTFOUND',代码:'ENOTFOUND',系统调用:'getaddrinfo',主机名:'https',主机:'https',端口:80},isOperational:true,errno:'ENOTFOUND',代码:'ENOTFOUND',系统调用:'getaddrinfo',主机名:'https',主机:'https',端口:80}

那么我如何通过 https 和 bitcoin-core 连接到比特币节点呢?

标签: bitcoinbitcoindbitcoin-testnetbitcoinlib

解决方案


Bitcoin Core 的 JSON RPC API 不支持 HTTPS。但是,您可以使其(在服务器上)只能通过 localhost ( rpcallowip=127.0.0.1) 访问。您可以编写一个包装器(例如 PHP)并通过 HTTPS Web 服务器运行它。


推荐阅读