> php教程 > PHP源码 > 본문

php 模拟用户POST GET源代码

WBOY
풀어 주다: 2016-06-08 17:26:27
원래의
1637명이 탐색했습니다.

下面的代码使用两种方式来调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);

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!