Closed zelding closed 7 years ago
please provide more informations about the returned response object
Here is the response var_dump:
object(Symfony\Component\HttpFoundation\Response)[2281]
public 'headers' =>
object(Symfony\Component\HttpFoundation\ResponseHeaderBag)[2282]
protected 'computedCacheControl' =>
array (size=1)
'no-cache' => boolean true
protected 'cookies' =>
array (size=0)
empty
protected 'headerNames' =>
array (size=8)
'cache-control' => string 'Cache-Control' (length=13)
'date' => string 'Date' (length=4)
'server' => string 'Server' (length=6)
'content-type' => string 'Content-Type' (length=12)
'content-length' => string 'Content-Length' (length=14)
'connection' => string 'Connection' (length=10)
'via' => string 'Via' (length=3)
'strict-transport-security' => string 'Strict-Transport-Security' (length=25)
protected 'headers' =>
array (size=8)
'cache-control' =>
array (size=1)
0 => string 'no-cache' (length=8)
'date' =>
array (size=1)
0 => string 'Fri, 04 Nov 2016 12:29:29 GMT' (length=29)
'server' =>
array (size=1)
0 => string 'nginx/1.6.2' (length=11)
'content-type' =>
array (size=1)
0 => string 'application/json' (length=16)
'content-length' =>
array (size=1)
0 => string '3' (length=1)
'connection' =>
array (size=1)
0 => string 'keep-alive' (length=10)
'via' =>
array (size=1)
0 => string '1.1 vegur' (length=9)
'strict-transport-security' =>
array (size=1)
0 => string 'max-age=500' (length=11)
protected 'cacheControl' =>
array (size=0)
empty
protected 'content' => string '{} ' (length=3)
protected 'version' => string '1.0' (length=3)
protected 'statusCode' => int 200
protected 'statusText' => string 'OK' (length=2)
protected 'charset' => null
maybe the destination api only accepts 'application/json' content-type
try:
$restClient->post(
$someApiUrl . "?" . http_build_query($someArray),
json_encode($someOtherArray)
);
if not: Try to provide a full bunch of informations. example $someArray example $someOtherArray example $someApiUrl Target Api authentication seems to be correct because the api answers with a HTTP_OK
I've tried it with raw curl
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($someOtherArray));
json payload didn't made a difference.
Examples:
$someArray = ['token' => "a0b1c2d3e4f5"];
$someotherArray = [
'value1' => 'someString',
'value2' => 'someOtherString',
'value3' => 2.7,
'value4' => 34
];
$someApiUrl = 'https://host.net/api/v1/model/id/something';
Than it should work: CiRestClientBundle does nothing else
/**
* sets the payload
*
* @param $payload
* @return Curl
*/
private function setPayload($payload) {
$this->curlOptionsHandler->setOption(CURLOPT_POSTFIELDS, $payload);
return $this;
}
Maybe you forgot to set other options. Like this for json:
circle_rest_client:
curl:
defaults:
CURLOPT_HTTPHEADER: [ 'Content-Type: application/json' ]
That was it, thank you!
I left out the whole configuration, once i set
CURLOPT_HTTPHEADER: [ 'Content-Type: application/x-www-form-urlencoded' ]
it was fine.
Nice. This can be closed .
Thank you Timo for figuring that out. Closed.
Please clarify this for me: I'm using a POST request which has a query parameter also, but the payload doesn't seem to get through. (Both arrays are key-value pairs)