mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-22 12:36:02 +03:00
Do not use json request body (#313)
Build a query encoded request strings and set proper headers.
This commit is contained in:
parent
9e19f12a3d
commit
1222104e54
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user