-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathphp_curl_func.php
More file actions
34 lines (31 loc) · 840 Bytes
/
php_curl_func.php
File metadata and controls
34 lines (31 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
/**
* curl辅助函数
* @author levinxo
*/
//post方式提交获取数据
function curl_post($url='', $postdata='', $options=array()){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
if (!empty($options)){
curl_setopt_array($ch, $options);
}
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
//get方式提交获取数据
function curl_get($url='', $options=array()){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
if (!empty($options)){
curl_setopt_array($ch, $options);
}
$data = curl_exec($ch);
curl_close($ch);
return $data;
}