跳转到主内容
websoft网络软件专家 - 深耕网络技术,打造实用软件!

PHP中使用socket方式GET、POST数据实例教程

这篇文章主要介绍了 php 中使用socket方式get、post数据实例,本文分别给出get方式和post方式的代码实例,需要的朋友可以参考下 1. 使用 PHP 获得网页内容 GET方式 代码如下:
\n"; return false; } else { $out = "GET $path HTTP/1.1\r\n"; $out .= "Host: $host\r\n"; $out .= "Connection: Close\r\n\r\n"; $ret = ""; fwrite($fp, $out); while (!feof($fp)) { $ret .= fgets($fp, 128); } fclose($fp); } return true; } ?>
2. 使用 PHP 向页面 POST 数据 PHP 8.5.5 PHP 8.5.5 是 PHP 8.5 分支的维护更新版本。该版本延续了“小步快跑”的迭代逻辑,通过深度错误修复、底层性能微调以及安全加固,旨在为开发者提供一个更健壮、更高效的运行环境。该版本严格遵守语义化版本规范,不包含破坏性变更。 下载 代码如下:
\n"; return false; } else { $out = "POST $path HTTP/1.1\r\n"; $out .= "Host: $host\r\n"; $out .= "Content-Type: application/x-www-form-urlencoded\r\n"; $out .= "Content-Length: ".strlen($data)."\r\n"; $out .= "Connection: Keep-Alive\r\n\r\n"; $out .= $data; $ret = ""; fwrite($fp, $out); while (!feof($fp)) { $ret .= fgets($fp, 128); } fclose($fp); } return true; } ?>
如果post报错,把$out .= "Connection: Keep-Alive\r\n\r\n";中的Keep-Alive改成Close

相关文章