php 模拟用户POST GET源代码
if(function_exists('curl_init'))
{
$ch = curl_init();
curl_setopt($ch, curlopt_url, $url_with_get);
curl_setopt($ch, curlopt_post, 1);
curl_setopt($ch, curlopt_postfields, $post);
curl_setopt($ch, curlopt_returntransfer, true);
$result = curl_exec($ch);
curl_close($ch);
}
else
{
$content = http_build_query($post)
$content_length = strlen($content);
$context =
array('http' =>
array('method' => 'post',
'user_agent' => $user_agent,
'header' => 'content-type: ' . $content_type . " " .
'content-length: ' . $content_length,
'content' => $content));
$context_id = stream_context_create($context);
$sock = fopen($url_with_get, 'r', false, $context_id);
$result = '';
if ($sock)
{
while (!feof($sock))
$result .= fgets($sock, 4096);
fclose($sock);
}
return $result;
}
}
测试代码
代码如下 | 复制代码 |
|
本文地址:http://www.phprm.com/code/34020.html
转载随意,但请附上文章地址:-)