Authored by ziy

修改curl get传参问题

... ... @@ -18,12 +18,7 @@ class CurlAbstract
$params = http_build_query($data, '', '&');
}
if (strpos($url, '?') === false) {
if (!empty($params) && substr_compare($url, '/', -1)) {
$url = $url . '/?' . $params;
} else if (!empty($params)) {
$url = $url . '?' . $params;
}
$url = $url . '?' . $params;
} else {
if (!empty($params)) {
$url = $url . '&' . $params;
... ...
... ... @@ -64,14 +64,29 @@ class CurlMulti extends CurlAbstract
* @return $this
* @throws Exception
*/
public function call($url, $callback, $data)
public function get($url, $callback, array $data = array())
{
$ch = curl_init($url);
$ch = curl_init(self::makeUrl($url, $data));
$this->addHandle($ch, $callback, $data, $this->wait_for_connect);
return $this;
}
/**
* 调用
* @param $url
* @param $callback
* @param $data
* @return $this
* @throws Exception
*/
public function post($url, $callback, $data)
{
$this->callRest($url, 'POST', $callback, $data);
return $this;
}
/**
* rest 请求方法
* @param $url
* @param $method
... ... @@ -86,20 +101,23 @@ class CurlMulti extends CurlAbstract
case 'POST':
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-HTTP-Method-Override: POST"));
$header = array_merge($this->headerData, array("X-HTTP-Method-Override: POST"));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
if ($data != null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
break;
case 'DELETE':
$ch = curl_init(self::makeUrl($url, $data));
$header = array_merge($this->headerData, array("X-HTTP-Method-Override: DELET"));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-HTTP-Method-Override: DELET"));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
break;
case 'PUT':
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-HTTP-Method-Override: PUT"));
$header = array_merge($this->headerData, array("X-HTTP-Method-Override: PUT"));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($data != null) {
$params = http_build_query($data, '', '&');
... ... @@ -109,7 +127,8 @@ class CurlMulti extends CurlAbstract
break;
case 'GET':
$ch = curl_init(self::makeUrl($url, $data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-HTTP-Method-Override: GET"));
$header = array_merge($this->headerData, array("X-HTTP-Method-Override: GET"));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
break;
}
$this->addHandle($ch, $callback, $data, $this->wait_for_connect);
... ...