-
Notifications
You must be signed in to change notification settings - Fork 0
/
curl.php
50 lines (41 loc) · 1.42 KB
/
curl.php
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
//echo MyCurl::get("http://www.baidu.com");
class MyCurl
{
public static function get($url)
{
//创建curl资源
$ch = curl_init() ;
//设置参数
curl_setopt($ch,CURLOPT_URL,$url);//设置请求地址
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);//设置是否返回数据
curl_setopt($ch,CURLOPT_HEADER,false);//是否显示请求头
curl_setopt($ch,CURLOPT_TIMEOUT,10);//设置超时时间,秒
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);//是否启用ssl验证
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);//是否验证主机
//发起请求
$content = curl_exec($ch);
//关闭
curl_close($ch);
return $content;
}
public static function post($url,$data)
{
//创建curl资源
$ch = curl_init() ;
//设置参数
curl_setopt($ch,CURLOPT_URL,$url);//设置请求地址
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);//设置是否返回数据
curl_setopt($ch,CURLOPT_HEADER,false);//是否显示请求头
curl_setopt($ch,CURLOPT_TIMEOUT,10);//设置超时时间,秒
curl_setopt($ch,CURLOPT_POST,true);//设置post请求
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);//设置post请求参数
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);//是否启用ssl验证
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);//是否验证主机
//发起请求
$content = curl_exec($ch);
//关闭
curl_close($ch);
return $content;
}
}