发送短信还可以有这样的操作!!涨姿势 public function Post($data, $target){ $url_info = parse_url($target); $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n"; $httpheader .= "Host:" . $url_info['host'] . "\r\n"; $httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n"; $httpheader .= "Content-Length:" . strlen($data) . "\r\n"; $httpheader .= "Connection:close\r\n\r\n"; //$httpheader .= "Connection:Keep-Alive\r\n\r\n"; $httpheader .= $data; $fd = fsockopen($url_info['host'], 80); fwrite($fd, $httpheader); $gets = ""; while(!feof($fd)) { $gets .= fread($fd, 128); } fclose($fd); if($gets != ''){ $start = strpos($gets, '<?xml'); if($start > 0) { $gets = substr($gets, $start); } } return $gets; }
下面复制简书的
链接:https://www.jianshu.com/p/a13503fb9872
fsockopen(主机名称,端口号码,错误号的接受变量,错误提示的接受变量,超时时间)
主机名称: 就是你需要发送数据的目的地;
端口号: 就是这个目的程序会在哪个端口等着你的数据;
错误号接受变量: 这个是如果建立socket不成功的时候返回的错误编号;
错误提示的变量: 是错误的时候返回的错误提示信息;
超时时间: 就是post数据之后如果对方没有回应信息,等待的最长时间。
$out里面变量含义:给目的地址一个协议串。
\r\n的含义:fgets会获取文件描述符$fp的当前的128(也可能是别的常数)个字节,如果还没有到128个字节遇到换行符了,则只返回换行符及换行符之前的内容。
fsockopen()将返回一个文件句柄,之后可以被其他文件类函数调用(例如:fgets(),fgetss(),fwrite(),fclose()还有feof())。如果调用失败,将返回FALSE。
使用fsockopen()函数比fopen()函数的优点:fopen()只会在PHP中已经将allow_url_fopen设置为真时才能使用,而fsockopen()并没有限制。