diff --git a/src/Mailgun/Api/HttpApi.php b/src/Mailgun/Api/HttpApi.php index 467689c..e7fcb39 100644 --- a/src/Mailgun/Api/HttpApi.php +++ b/src/Mailgun/Api/HttpApi.php @@ -139,7 +139,9 @@ abstract class HttpApi */ protected function httpPost($path, array $parameters = [], array $requestHeaders = []) { - return $this->httpPostRaw($path, $this->createJsonBody($parameters), $requestHeaders); + $requestHeaders['Content-Type'] = 'application/x-www-form-urlencoded'; + + return $this->httpPostRaw($path, $this->createRequestBody($parameters), $requestHeaders); } /** @@ -175,9 +177,11 @@ abstract class HttpApi */ protected function httpPut($path, array $parameters = [], array $requestHeaders = []) { + $requestHeaders['Content-Type'] = 'application/x-www-form-urlencoded'; + try { $response = $this->httpClient->sendRequest( - $this->requestBuilder->create('PUT', $path, $requestHeaders, $this->createJsonBody($parameters)) + $this->requestBuilder->create('PUT', $path, $requestHeaders, $this->createRequestBody($parameters)) ); } catch (HttplugException\NetworkException $e) { throw HttpServerException::networkError($e); @@ -197,9 +201,11 @@ abstract class HttpApi */ protected function httpDelete($path, array $parameters = [], array $requestHeaders = []) { + $requestHeaders['Content-Type'] = 'application/x-www-form-urlencoded'; + try { $response = $this->httpClient->sendRequest( - $this->requestBuilder->create('DELETE', $path, $requestHeaders, $this->createJsonBody($parameters)) + $this->requestBuilder->create('DELETE', $path, $requestHeaders, $this->createRequestBody($parameters)) ); } catch (HttplugException\NetworkException $e) { throw HttpServerException::networkError($e); @@ -215,8 +221,8 @@ abstract class HttpApi * * @return null|string */ - protected function createJsonBody(array $parameters) + protected function createRequestBody(array $parameters) { - return (count($parameters) === 0) ? null : json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0); + return (count($parameters) === 0) ? null : http_build_query($parameters); } }