mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-09-05 07:16:27 +00:00
Fix #10: Remove trailing ? from request urls
This commit is contained in:
+8
-4
@@ -36,13 +36,13 @@ class Curl {
|
||||
}
|
||||
|
||||
public function get($url, $data=array()) {
|
||||
$this->setopt(CURLOPT_URL, $url . '?' . http_build_query($data));
|
||||
$this->setopt(CURLOPT_URL, $this->_buildURL($url, $data));
|
||||
$this->setopt(CURLOPT_HTTPGET, TRUE);
|
||||
return $this->_exec();
|
||||
}
|
||||
|
||||
public function post($url, $data=array()) {
|
||||
$this->setopt(CURLOPT_URL, $url);
|
||||
$this->setopt(CURLOPT_URL, $this->_buildURL($url));
|
||||
$this->setopt(CURLOPT_POST, TRUE);
|
||||
$this->setopt(CURLOPT_POSTFIELDS, $this->_postfields($data));
|
||||
return $this->_exec();
|
||||
@@ -56,14 +56,14 @@ class Curl {
|
||||
}
|
||||
|
||||
public function patch($url, $data=array()) {
|
||||
$this->setopt(CURLOPT_URL, $url);
|
||||
$this->setopt(CURLOPT_URL, $this->_buildURL($url));
|
||||
$this->setopt(CURLOPT_CUSTOMREQUEST, 'PATCH');
|
||||
$this->setopt(CURLOPT_POSTFIELDS, $data);
|
||||
return $this->_exec();
|
||||
}
|
||||
|
||||
public function delete($url, $data=array()) {
|
||||
$this->setopt(CURLOPT_URL, $url . '?' . http_build_query($data));
|
||||
$this->setopt(CURLOPT_URL, $this->_buildURL($url, $data));
|
||||
$this->setopt(CURLOPT_CUSTOMREQUEST, 'DELETE');
|
||||
return $this->_exec();
|
||||
}
|
||||
@@ -121,6 +121,10 @@ class Curl {
|
||||
return implode('&', $query);
|
||||
}
|
||||
|
||||
private function _buildURL($url, $data=array()) {
|
||||
return $url . (empty($data) ? '' : '?' . http_build_query($data));
|
||||
}
|
||||
|
||||
private function _postfields($data) {
|
||||
if (is_array($data)) {
|
||||
if (is_array_multidim($data)) {
|
||||
|
||||
+7
-1
@@ -190,9 +190,15 @@ class CurlTest extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
|
||||
public function testRequestURL() {
|
||||
$test = new Test();
|
||||
$this->assertFalse(substr($test->server('request_uri', 'GET'), -1) === '?');
|
||||
$test = new Test();
|
||||
$this->assertFalse(substr($test->server('request_uri', 'POST'), -1) === '?');
|
||||
$test = new Test();
|
||||
$this->assertFalse(substr($test->server('request_uri', 'GET'), -1) === '?');
|
||||
$this->assertFalse(substr($test->server('request_uri', 'PUT'), -1) === '?');
|
||||
$test = new Test();
|
||||
$this->assertFalse(substr($test->server('request_uri', 'PATCH'), -1) === '?');
|
||||
$test = new Test();
|
||||
$this->assertFalse(substr($test->server('request_uri', 'DELETE'), -1) === '?');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user