closes #26
This commit is contained in:
@@ -168,11 +168,13 @@
|
|||||||
} else {
|
} else {
|
||||||
$url .= "?";
|
$url .= "?";
|
||||||
}
|
}
|
||||||
|
Unirest::http_build_query_for_curl($body, $postBody);
|
||||||
|
$url .= http_build_query($postBody);
|
||||||
|
|
||||||
foreach ($body as $parameter => $val) {
|
//foreach ($body as $parameter => $val) {
|
||||||
$url .= $parameter . "=" . $val . "&";
|
// $url .= $parameter . "=" . $val . "&";
|
||||||
}
|
//}
|
||||||
$url = substr($url, 0, strlen($url) - 1);
|
//$url = substr($url, 0, strlen($url) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_setopt ($ch, CURLOPT_URL, Unirest::encodeUrl($url));
|
curl_setopt ($ch, CURLOPT_URL, Unirest::encodeUrl($url));
|
||||||
@@ -206,6 +208,18 @@
|
|||||||
return new HttpResponse($httpCode, $body, $header);
|
return new HttpResponse($httpCode, $body, $header);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function getArrayFromQuerystring($querystring) {
|
||||||
|
$pairs = explode("&", $querystring);
|
||||||
|
$vars = array();
|
||||||
|
foreach ($pairs as $pair) {
|
||||||
|
$nv = explode("=", $pair);
|
||||||
|
$name = $nv[0];
|
||||||
|
$value = $nv[1];
|
||||||
|
$vars[$name] = $value;
|
||||||
|
}
|
||||||
|
return $vars;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure that a URL is encoded and safe to use with cURL
|
* Ensure that a URL is encoded and safe to use with cURL
|
||||||
* @param string $url URL to encode
|
* @param string $url URL to encode
|
||||||
@@ -222,8 +236,7 @@
|
|||||||
$query = (isset($url_parsed['query']) ? $url_parsed['query'] : null);
|
$query = (isset($url_parsed['query']) ? $url_parsed['query'] : null);
|
||||||
|
|
||||||
if ($query != null) {
|
if ($query != null) {
|
||||||
parse_str($url_parsed['query'], $query_parsed);
|
$query = '?' . http_build_query(Unirest::getArrayFromQuerystring($url_parsed['query']));
|
||||||
$query = '?' . http_build_query($query_parsed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($port && $port[0] != ":")
|
if ($port && $port[0] != ":")
|
||||||
|
|||||||
@@ -16,6 +16,36 @@ class UnirestTest extends UnitTestCase
|
|||||||
$this->assertEqual("thefosk", $args->nick);
|
$this->assertEqual("thefosk", $args->nick);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetWithDots()
|
||||||
|
{
|
||||||
|
$response = Unirest::get("http://httpbin.org/get", array( "Accept" => "application/json" ),
|
||||||
|
array(
|
||||||
|
"user.name" => "Mark",
|
||||||
|
"nick" => "thefosk"
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertEqual(200, $response->code);
|
||||||
|
|
||||||
|
$args = $response->body->args;
|
||||||
|
$this->assertEqual("Mark", $args->{"user.name"});
|
||||||
|
$this->assertEqual("thefosk", $args->nick);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetWithDots2()
|
||||||
|
{
|
||||||
|
$response = Unirest::get("http://httpbin.org/get", array( "Accept" => "application/json" ),
|
||||||
|
array(
|
||||||
|
"user.name" => "Mark Bond",
|
||||||
|
"nick" => "thefosk"
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertEqual(200, $response->code);
|
||||||
|
|
||||||
|
$args = $response->body->args;
|
||||||
|
$this->assertEqual("Mark+Bond", $args->{"user.name"});
|
||||||
|
$this->assertEqual("thefosk", $args->nick);
|
||||||
|
}
|
||||||
|
|
||||||
public function testPost()
|
public function testPost()
|
||||||
{
|
{
|
||||||
$response = Unirest::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
|
$response = Unirest::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
|
||||||
@@ -31,6 +61,21 @@ class UnirestTest extends UnitTestCase
|
|||||||
$this->assertEqual("thefosk", $form->nick);
|
$this->assertEqual("thefosk", $form->nick);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPostWithDots()
|
||||||
|
{
|
||||||
|
$response = Unirest::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
|
||||||
|
array(
|
||||||
|
"user.name" => "Mark",
|
||||||
|
"nick" => "thefosk"
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertEqual(200, $response->code);
|
||||||
|
|
||||||
|
$form = $response->body->form;
|
||||||
|
$this->assertEqual("Mark", $form->{"user.name"});
|
||||||
|
$this->assertEqual("thefosk", $form->nick);
|
||||||
|
}
|
||||||
|
|
||||||
public function testUpload() {
|
public function testUpload() {
|
||||||
$response = Unirest::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
|
$response = Unirest::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
|
||||||
array(
|
array(
|
||||||
|
|||||||
Reference in New Issue
Block a user