proactive system password reco php 模拟POST|GET操作实现代码
Jul 29, 2016 am 08:43 AM最近开发social game,发现使用这个东西还是比较平凡,这里做个总结,一来为自己留点记忆,另外希望对大家有帮助.
首先来看看需求,如果我们开发facebook上social game,需要调用它的接口来获得用户在facebook上的好友信息。这个时候我们就要访问facebook提供的一个地址呢,当然你在访问他的时候,他需要对你的访问做验证,防止非法请求。这个时候就得向其post|get一些参数。
如下面的地址:
复制代码 代码如下:
$url_with_get= "http://api.facebook.com/restserver.php?method=facebook.friends.get&sessi
$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;
}
}
上面的代码使用两种方式来调facebook的接口,第一种县判断用户的环境是否开启了curl库,开启了这个库,就采用这种方式来获取请求。里面详细的参数讲解大家可以参考手册。
这里提示一点,由于我们通常情况下需要获得调用接口的返回结果,所以要设置CURLOPT_RETURNTRANSFER这个值,将结果返回到变量中。
第二种方式是直观,将url请求转化为文件流来处理。
以上就介绍了proactive system password reco php 模拟POST|GET操作实现代码,包括了proactive system password reco方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Heißer Artikel

Hot-Tools-Tags

Heißer Artikel

Heiße Artikel -Tags

Notepad++7.3.1
Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version
Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1
Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6
Visuelle Webentwicklungstools

SublimeText3 Mac-Version
Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Heiße Themen

11 beste PHP -URL -Shortener -Skripte (kostenlos und Premium)

Arbeiten mit Flash -Sitzungsdaten in Laravel

Erstellen Sie eine React -App mit einem Laravel -Back -Ende: Teil 2, reagieren

Vereinfachte HTTP -Reaktion verspottet in Laravel -Tests

Curl in PHP: So verwenden Sie die PHP -Curl -Erweiterung in REST -APIs

12 Beste PHP -Chat -Skripte auf Codecanyon

Ankündigung von 2025 PHP Situation Survey
