phpにおけるcurlパッケージ
4831 ワード
public static function postcurl($data){
$ch = curl_init();
// curl
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// , 。
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
// SSL
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
if($data['type'] == "post") {
// POST , :application/x-www-form-urlencoded, 。
$fields_string = '';
foreach($data['fileds'] as $key => $value){
$fields_string.=$key.'='.$value.'&';
}
$fields_string = rtrim($fields_string , '&');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $data['url']);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
}else{
curl_setopt($ch, CURLOPT_URL, $data['url']);
}
$res = curl_exec($ch);
return $res;
}