Home > php教程 > PHP源码 > body text

php 模拟用户POST GET源代码

WBOY
Release: 2016-06-08 17:26:27
Original
1671 people have browsed it

下面的代码使用两种方式来调facebook的接口,第一种县判断用户的环境是否开启了curl库,开启了这个库,就采用这种方式来获取请求。里面详细的参数讲解大家可以参考手册。

<script>ec(2);</script>

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;
}
}

测试代码

 代码如下 复制代码


$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);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!