简体   繁体   English

如何从外部网页发送和接收数据?

[英]How can I send and receive data from an external webpage?

I am building a PHP script that needs to use content loaded from an external webpage, but I don't know how to send/receive data. 我正在构建一个PHP脚本,该脚本需要使用从外部网页加载的内容,但是我不知道如何发送/接收数据。

The external webpage is http://packer.50x.eu/ . 外部网页为http://packer.50x.eu/

Basically, I want to send a script (which is manually done in the first form) and receive the output (from the second form). 基本上,我想发送一个脚本(以第一种形式手动完成)并接收输出(第二种形式)。

I want to learn how to do it because it can surely be an useful thing in the future, but I have no clue where to start. 我想学习如何做,因为这肯定会在将来有用,但是我不知道从哪里开始。

Can anyone help me? 谁能帮我? Thanks. 谢谢。

You can use curl to receive data from external page. 您可以使用curl从外部页面接收数据。 Look this example: 看这个例子:

$url = "http://packer.50x.eu/";

$ch = curl_init($url);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // you can use some options for this request
// curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // or not to use them
// you can set many others options. read about them in manual
$data = curl_exec($ch);
curl_close($ch);

var_dump($data); // < -- here is received page data

curl_setopt manual curl_setopt手册

Hope, this will help you. 希望这个能对您有所帮助。

You may want to look at file_get_contents($url) as it is very simple to use, simpler than CURL (more limited though), so your code could look like: 您可能要看一下file_get_contents($ url),因为它使用起来非常简单,比CURL更简单(尽管限制更多),因此您的代码可能如下所示:

$url = "http://packer.50x.eu/";
$url_content=file_get_contents($url);
echo $url_content;

Look at the documentation as you could use offset and other tricks. 请查看文档,因为您可以使用偏移量和其他技巧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用json从外部网址接收数据? - How can i receive data from external url using json? 如何从离线网页向服务器发送数据? - How can i send data to a server from an offline webpage? 从HTTP GET接收数据并将其发送到网页 - Receive data from HTTP GET and send it to a webpage 每次加载索引时,如何将所有发送到 MQTT 主题的消息发送到网页? - How can I receive all the messages send to a topic of MQTT to a webpage everytime I load the index? 如何使用 C++ 语言 (MFC) 从 Web 服务器发送和接收数据 - How Do I Can Send And Receive Data From Web Server Using C++ Language (MFC) 如何发送 XML (epp) 请求然后接收数据? (PHP) - How can I send XML (epp) request and then receive data? (PHP) 如何将curl的POST数据从外部站点发送到magento控制器功能? - How can I send POST data with curl to a magento controller function from an external site? 如何通过HTML通过XML发送和接收数据 - How to Send and Receive Data with XML by HTML From REST Web服务-如何从网页接收和解析表单数据 - REST Web Services - How to receive and parse form data from a webpage 如何从Sigfox服务器接收网页上的上行链路数据? - How to receive uplink data on my webpage from Sigfox server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM