Showing posts with label curl. Show all posts
Showing posts with label curl. Show all posts

Thursday, October 22, 2009

curl Postデータ

$data = array(
'MAX' =>'20',
'NAME' => '田中',
'ADDRESS' => 'test@test.com',
);

$post_words=array();
foreach( $data as $key => $value ){
$post_words[] = $key. "=" .$value;
}
$post_word = implode("&", $post_words);

curl_setopt($ch,CURLOPT_POSTFIELDS,$post_word);

Wednesday, October 21, 2009

curl とCookie

$useragent = 'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
$cookie_save_file = 'cookie_data';

$url = 'http://example.com/test.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
curl_setopt ($ch,CURLOPT_POST,1);
$post_word = "input=了承";
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_word);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_save_file);// 読み込まれるファイル
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_save_file);// 内容が保存される。
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
$content = curl_exec($ch);
curl_close($ch);

echo $content;

Thursday, October 16, 2008

curlによるSSL sample

$ch=curl_init();
$url = "https://hoge.coom/authentication_email.php";
curl_setopt ($ch,CURLOPT_URL, $url );
curl_setopt ($ch,CURLOPT_POST,1);
$post = "email=".$_POST['email'];
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
// curl_setopt ($ch,CURLOPT_RETURNTRANSFER, FALSE);
curl_setopt ($ch,CURLOPT_RETURNTRANSFER, 1);

$ret = curl_exec($ch);

if (empty($ret)) {
// some kind of an error happened
die(curl_error($ch));
curl_close($ch); // close cURL handler
} else {
echo $ret;
// $info = curl_getinfo($ch);
curl_close($ch); // close cURL handler
}