Check if $body is traversable before recursively sanitizing (allows for raw JSON body)
Add testRawPost()
This commit is contained in:
@@ -172,8 +172,12 @@
|
|||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
if ($httpMethod != HttpMethod::GET) {
|
if ($httpMethod != HttpMethod::GET) {
|
||||||
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, $httpMethod);
|
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, $httpMethod);
|
||||||
|
if( is_array($body) || $body instanceof Traversable ) {
|
||||||
Unirest::http_build_query_for_curl($body, $postBody);
|
Unirest::http_build_query_for_curl($body, $postBody);
|
||||||
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postBody);
|
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postBody);
|
||||||
|
} else {
|
||||||
|
curl_setopt ($ch, CURLOPT_POSTFIELDS, $body);
|
||||||
|
}
|
||||||
} else if (is_array($body)) {
|
} else if (is_array($body)) {
|
||||||
if (strpos($url,'?') !== false) {
|
if (strpos($url,'?') !== false) {
|
||||||
$url .= "&";
|
$url .= "&";
|
||||||
|
|||||||
@@ -90,6 +90,19 @@ class UnirestTest extends UnitTestCase
|
|||||||
$this->assertEqual("thefosk", $form->nick);
|
$this->assertEqual("thefosk", $form->nick);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRawPost()
|
||||||
|
{
|
||||||
|
$response = Unirest::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
|
||||||
|
json_encode(array(
|
||||||
|
"author" => "Sam Sullivan"
|
||||||
|
)));
|
||||||
|
|
||||||
|
$this->assertEqual(200, $response->code);
|
||||||
|
|
||||||
|
$json = $response->body->json;
|
||||||
|
$this->assertEqual("Sam Sullivan", $json->author);
|
||||||
|
}
|
||||||
|
|
||||||
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