【问题标题】:The PHP file_get_contents command does not work when read data from the Node.js server从 Node.js 服务器读取数据时 PHP file_get_contents 命令不起作用
【发布时间】:2018-08-23 14:22:33
【问题描述】:

我尝试将消息从 PHP 服务器发送到 Node.js 服务器。 Node.js 服务器的目的是使用 Socket.io 和 Express 转发消息。

$NodePage = file_get_contents($NodeServer. "/index.html?&message=". $message);

服务器总是返回空字符串并且不发送消息。浏览器中的相同 URL 工作正常,并且消息已正确发送。我也尝试了重定向命令。

header("Location: http://xxxxxxx.fi/index.html?message=". $message);

也返回空字符串。在网络浏览器中工作正常。我从 C# 客户端进行 PHP 调用。

       HtmlWeb web = new HtmlWeb();
       string tempURL = _url + _htmlMessageStr +
                "?message=" + msg.fullMessage) ;

       HtmlDocument doc = web.Load(tempURL);
       HtmlNodeCollection tags = 
       doc.DocumentNode.SelectNodes(_nodeText);

       _retVal = parse(tags[0].InnerHtml);

除节点数据(空字符串)外,任何其他数据都可以来自 PHP。我尝试从其他 Node.js 服务器检索数据并正确恢复数据。我的 Node.js 服务器出了点问题,但是什么?服务器由托管公司托管。服务器不运行除 Node.js 之外的任何东西。

【问题讨论】:

标签: javascript c# php node.js


【解决方案1】:

这需要在 php.ini 中启用。您正在搜索的选项是“allow_url_fopen”并将其设置为 true。

http://php.net/manual/en/filesystem.configuration.php

【讨论】:

    【解决方案2】:

    我发现了问题。您不能使用 file_get_contents 命令将 Socket.io 连接到 Node.js 服务器。您需要连接到 socket.io。

    这篇文章解释了如何做到这一点。 enter link description here

    【讨论】:

      猜你喜欢
      • 2021-08-12
      • 2013-10-02
      • 1970-01-01
      • 2012-11-15
      • 1970-01-01
      • 2012-10-13
      • 2019-01-27
      • 2015-11-04
      • 1970-01-01
      相关资源
      最近更新 更多