|
|
|
2011-06-21 11:10:291891
|
CURL À» ÀÌ¿ëÇÑ GET/POST º¯¼ö Àü¼Û |
|
È£¼®
|
|
| ÀÏ¹Ý | |
|
CURL À» ÀÌ¿ëÇÑ GET/POST º¯¼ö Àü¼Û
CURL, Client URL Library
$cu = curl_init();
// µ¥ÀÌŸ¸¦
º¸³¾ URL ¼³Á¤
curl_setopt($cu, CURLOPT_URL,$URL);
// ÇØ´ç µ¥ÀÌŸ¸¦ º¸³¾ http head
Á¤ÀÇ : »èÁ¦Çصµ µÇ±äÇÔ
curl_setopt($cu, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible;
MSIE 5.01; Windows NT 5.0)");
// µ¥ÀÌŸ¸¦ get/post ·Î º¸³¾Áö ¼³Á¤
CURLOPT_GET/CURLOPT_POST
curl_setopt($cu, CURLOPT_POST,1);
// º¸³¾ µ¥ÀÌŸ¸¦
¼³Á¤ Çü½ÄÀº GET ¹æ½ÄÀ¸·Î ¼³Á¤
// ex) $vars =
"arg=$arg1&arg2=$arg2&arg3=$arg3";
curl_setopt($cu,
CURLOPT_POSTFIELDS,$vars);
// REQUEST ¿¡ ´ëÇÑ °á°ú°ªÀ» ¹ÞÀ»°ÇÁö üũ
curl_setopt($cu, CURLOPT_RETURNTRANSFER,1);
#Resource ID ÇüÅ·Π³Ñ¾î¿È ::
³»Àå ÇÔ¼ö curl_errno ·Î üũ
// REQUEST ¿¡ ´ëÇÑ °á°ú°ªÀ» ¹Þ´Â ½Ã°£Å¸ÀÓ ¼³Á¤
curl_setopt($cu,
CURLOPT_TIMEOUT,100);
$output = curl_exec($cu);
// ½ÇÇà
$succeeded = (
curl_errno($cu) == 0 ) ? true : false;
curl_close($cu);
|
|
|
|
|
È£¼®
11-06-21 15:53
|
|
|
|
/**
* Send a POST requst using cURL
* @param string $url to request
* @param array $post values to send
* @param array $options for cURL
* @return string
*/
function curl_post($url, array $post = NULL, array $options = array())
{
$defaults = array(
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 4,
CURLOPT_POSTFIELDS => http_build_query($post)
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
}
/**
* Send a GET requst using cURL
* @param string $url to request
* @param array $get values to send
* @param array $options for cURL
* @return string
*/
function curl_get($url, array $get = NULL, array $options = array())
{
$defaults = array(
CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get),
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 4
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
} |
|
|
|
|
|
|
|