Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Mashape/unirest-php
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Jan 14, 2014
2 parents 8b184d9 + 9e48aa4 commit d0117b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/Unirest/Unirest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,13 @@ private static function request($httpMethod, $url, $body = NULL, $headers = arra

$ch = curl_init();
if ($httpMethod != HttpMethod::GET) {
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, $httpMethod);
Unirest::http_build_query_for_curl($body, $postBody);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postBody);
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, $httpMethod);
if( is_array($body) || $body instanceof Traversable ) {
Unirest::http_build_query_for_curl($body, $postBody);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postBody);
} else {
curl_setopt ($ch, CURLOPT_POSTFIELDS, $body);
}
} else if (is_array($body)) {
if (strpos($url,'?') !== false) {
$url .= "&";
Expand Down
13 changes: 13 additions & 0 deletions test/Unirest/UnirestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ public function testPostWithDots()
$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() {
$response = Unirest::post("http://httpbin.org/post", array( "Accept" => "application/json" ),
array(
Expand Down

0 comments on commit d0117b5

Please sign in to comment.