Authored by ziy

修改curl get传参问题

@@ -18,12 +18,7 @@ class CurlAbstract @@ -18,12 +18,7 @@ class CurlAbstract
18 $params = http_build_query($data, '', '&'); 18 $params = http_build_query($data, '', '&');
19 } 19 }
20 if (strpos($url, '?') === false) { 20 if (strpos($url, '?') === false) {
21 - if (!empty($params) && substr_compare($url, '/', -1)) {  
22 - $url = $url . '/?' . $params;  
23 - } else if (!empty($params)) {  
24 - $url = $url . '?' . $params;  
25 - }  
26 - 21 + $url = $url . '?' . $params;
27 } else { 22 } else {
28 if (!empty($params)) { 23 if (!empty($params)) {
29 $url = $url . '&' . $params; 24 $url = $url . '&' . $params;
@@ -64,14 +64,29 @@ class CurlMulti extends CurlAbstract @@ -64,14 +64,29 @@ class CurlMulti extends CurlAbstract
64 * @return $this 64 * @return $this
65 * @throws Exception 65 * @throws Exception
66 */ 66 */
67 - public function call($url, $callback, $data) 67 + public function get($url, $callback, array $data = array())
68 { 68 {
69 - $ch = curl_init($url); 69 + $ch = curl_init(self::makeUrl($url, $data));
70 $this->addHandle($ch, $callback, $data, $this->wait_for_connect); 70 $this->addHandle($ch, $callback, $data, $this->wait_for_connect);
71 return $this; 71 return $this;
72 } 72 }
73 73
74 /** 74 /**
  75 + * 调用
  76 + * @param $url
  77 + * @param $callback
  78 + * @param $data
  79 + * @return $this
  80 + * @throws Exception
  81 + */
  82 + public function post($url, $callback, $data)
  83 + {
  84 + $this->callRest($url, 'POST', $callback, $data);
  85 + return $this;
  86 + }
  87 +
  88 +
  89 + /**
75 * rest 请求方法 90 * rest 请求方法
76 * @param $url 91 * @param $url
77 * @param $method 92 * @param $method
@@ -86,20 +101,23 @@ class CurlMulti extends CurlAbstract @@ -86,20 +101,23 @@ class CurlMulti extends CurlAbstract
86 case 'POST': 101 case 'POST':
87 $ch = curl_init($url); 102 $ch = curl_init($url);
88 curl_setopt($ch, CURLOPT_POST, TRUE); 103 curl_setopt($ch, CURLOPT_POST, TRUE);
89 - curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-HTTP-Method-Override: POST")); 104 + $header = array_merge($this->headerData, array("X-HTTP-Method-Override: POST"));
  105 + curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
90 if ($data != null) { 106 if ($data != null) {
91 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 107 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
92 } 108 }
93 break; 109 break;
94 case 'DELETE': 110 case 'DELETE':
95 $ch = curl_init(self::makeUrl($url, $data)); 111 $ch = curl_init(self::makeUrl($url, $data));
  112 + $header = array_merge($this->headerData, array("X-HTTP-Method-Override: DELET"));
96 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); 113 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
97 - curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-HTTP-Method-Override: DELET")); 114 + curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
98 break; 115 break;
99 case 'PUT': 116 case 'PUT':
100 $ch = curl_init($url); 117 $ch = curl_init($url);
101 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); 118 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
102 - curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-HTTP-Method-Override: PUT")); 119 + $header = array_merge($this->headerData, array("X-HTTP-Method-Override: PUT"));
  120 + curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
103 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 121 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
104 if ($data != null) { 122 if ($data != null) {
105 $params = http_build_query($data, '', '&'); 123 $params = http_build_query($data, '', '&');
@@ -109,7 +127,8 @@ class CurlMulti extends CurlAbstract @@ -109,7 +127,8 @@ class CurlMulti extends CurlAbstract
109 break; 127 break;
110 case 'GET': 128 case 'GET':
111 $ch = curl_init(self::makeUrl($url, $data)); 129 $ch = curl_init(self::makeUrl($url, $data));
112 - curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-HTTP-Method-Override: GET")); 130 + $header = array_merge($this->headerData, array("X-HTTP-Method-Override: GET"));
  131 + curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
113 break; 132 break;
114 } 133 }
115 $this->addHandle($ch, $callback, $data, $this->wait_for_connect); 134 $this->addHandle($ch, $callback, $data, $this->wait_for_connect);