php 함수 두 개
11612 단어 PHP
1、http_build_query($params);
2、parse_str($r, $out);
curl 은 서버 에 http (s) 요청 을 보 내 는 데 사 용 됩 니 다.
1 /**
2 * HTTP
3 * @author xiaopengzhu <[email protected]>
4 * @version 2.0 2012-04-20
5 */
6 class Http
7 {
8 /**
9 * HTTP/HTTPS
10 * @param $url URL
11 * @param $params array('content'=>'test', 'format'=>'json');
12 * @param $method GET|POST
13 * @param $multi
14 * @param $extheaders
15 * @return string
16 */
17 public static function request( $url , $params = array(), $method = 'GET' , $multi = false, $extheaders = array())
18 {
19 if(!function_exists('curl_init')) exit('Need to open the curl extension');
20 $method = strtoupper($method);
21 $ci = curl_init();
22 curl_setopt($ci, CURLOPT_USERAGENT, 'PHP-SDK OAuth2.0');
23 curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 3);
24 curl_setopt($ci, CURLOPT_TIMEOUT, 3);
25 curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
26 curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false);
27 curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, false);
28 curl_setopt($ci, CURLOPT_HEADER, false);
29 $headers = (array)$extheaders;
30 switch ($method)
31 {
32 case 'POST':
33 curl_setopt($ci, CURLOPT_POST, TRUE);
34 if (!empty($params))
35 {
36 if($multi)
37 {
38 foreach($multi as $key => $file)
39 {
40 $params[$key] = '@' . $file;
41 }
42 curl_setopt($ci, CURLOPT_POSTFIELDS, $params);
43 $headers[] = 'Expect: ';
44 }
45 else
46 {
47 curl_setopt($ci, CURLOPT_POSTFIELDS, http_build_query($params));
48 }
49 }
50 break;
51 case 'DELETE':
52 case 'GET':
53 $method == 'DELETE' && curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
54 if (!empty($params))
55 {
56 $url = $url . (strpos($url, '?') ? '&' : '?')
57 . (is_array($params) ? http_build_query($params) : $params);
58 }
59 break;
60 }
61 curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE );
62 curl_setopt($ci, CURLOPT_URL, $url);
63 if($headers)
64 {
65 curl_setopt($ci, CURLOPT_HTTPHEADER, $headers );
66 }
67
68 $response = curl_exec($ci);
69 curl_close ($ci);
70 return $response;
71 }
72 }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
laravel에 yo에서 angularJs&coffeescript를 사용할 수 있도록 한다.먼저 yo 명령을 사용할 수 있어야하므로 아래에서 설치 global에 설치한 곳에서 laravel의 프로젝트 루트로 이동. 클라이언트 코드를 관리하는 디렉토리를 만들고 이동합니다. 클라이언트 환경 만들기 이것으로 히...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.