我尝试通过PHP将数据存储到ipfs,我使用curl与API通信,它在我的本地节点上工作正常,但我想使用www.example.com中的外部节点infura.io
但是由于某种原因,ipfs.infura.io拒绝我通过php连接,即使是一个简单的命令,比如...我已经在我的本地主机和几个服务器上试过了
下面是一个简单的端点,您可以在浏览器中打开它并获得输出
https://ipfs.infura.io:5001/api/v0/pin/add?arg=QmeGAVddnBSnKc1DLE7DLV9uuTqo5F7QbaveTjr45JUdQn
但是当我试图通过PHP打开它时,我得到了
无法连接到ipfs.infura.io端口5001:连接被拒绝
或使用其他方法(如file_get_contents)时
如果您有任何问题,请通过以下方式解决:无法打开流:连接被拒绝
我在本地主机和多个服务器上试过了,即使通过ssh命令行也得到了相同的结果
知道为什么会这样吗
下面是我代码的简化版本n
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,"https://ipfs.infura.io:5001/api/v0/pin/add?arg=QmeGAVddnBSnKc1DLE7DLV9uuTqo5F7QbaveTjr45JUdQn");
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
$res = curl_exec($curl);
if (curl_errno($curl)) {
$error_msg = curl_error($curl);
echo ('error ...');
echo ($error_msg);
exit();
}
curl_close($curl);
echo($res);
1条答案
按热度按时间628mspwn1#
为了连接
ipfs
节点,您需要有一个客户端库。客户端库自动格式化API响应,以匹配编程语言中使用的数据类型,并且还处理其他特定的通信规则。在JavaScript中,
则该客户端发出请求:
在php中,你可以使用这个包:https://github.com/cloutier/php-ipfs-api
选中此项以与infura交互:https://github.com/digitalkaoz/php-ipfs-api
此库需要cURL模块:
要从命令行使用此驱动程序,仅需提供选项(或将其保留,因为它是默认选项):
此驱动程序用于编程的客户端: