这篇文章主要为大家详细介绍了php 模拟POST|GET操作的简单示例,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小编小韵来看看吧!
最近开发social game,发现使用这个东西还是比较平凡,这里做个总结,一来为自己留点记忆,另外希望对大家有帮助.代码如下:
$url_with_get= "http://api.facebook.com/restserver.php?method=facebook.friends.get&session_key=&api_key=1232121311&v=1.0";
$post = array('sig'=>12312123234353);
代码如下:
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 . "\r\n" .
'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.q1010.com/173/13459-0.html
注:关于php 模拟POST|GET操作的简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。