标签:http io ar os for 数据 on cti ad
PHP模拟POST提交数据有file_get_contents、curl和socket,他们都可以通过模拟POST提交,实现POST数据传输。
file_get_contents模拟POST提交:
$arr=array(‘http’=>array(‘method’=>’POST’,’content’=>’name=wang&pwd=123′));
$result = file_get_contents(“www.wangzhiguang.com.cn”,false,stream_context_create($arr))
curl模拟POST提交:
$arr = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => array(‘name’=>’wang’,’pwd’=>’123′)
);
$ch = curl_init($url);
curl_setopt_array($ch, $arr);
$result = curl_exec($ch);
curl_close($ch);
socket来模拟POST提交:
$url = “www.wangzhiguang.com.cn”;
$host = 80;
$content = ‘name=wang&pwd=123′;
$fp = fsockopen($content, $host, $errno, $errstr);
$length = strlen($content);
$header = <<<HEADER
POST {$url} HTTP/1.1
Host: {$host}
Content-Type: application/x-www-form-urlencoded
Content-Length: {$length}
Connection: close
{$content}
HEADER;
fwrite($fp, $header);
while (!feof($fp)) {
$result .= fread($fp, 512);
}
$result = explode(“\r\n\r\n”, $result, 2);
connection: close和post数据之间要空一行
最好通过返回值$result你就可以看到发送状态了。
标签:http io ar os for 数据 on cti ad
原文地址:http://www.cnblogs.com/liuxinyufx/p/4101192.html