XF 2.0 HTTP Client Requests

Lukas W.

Well-known member
I'm currently running against a wall with this one. I have implemented a number of post requests to an API, all of which are working completely fine except for one.

The code looks as follows:
PHP:
[...]
$body = ['body' => [
    'secret' => $this->app->options()->klCHPrivateKey,
    'name' => $visitor = \XF::visitor()->user_id
]];

try {
    $userStats = $client->post('https://some.api.link/user/balance', $body)->json();

    \XF::dump($userStats);
}
[...]

The body is correctly populated with the secret and the name. However when I send the post request to their API, it returns 'a parameter is missing', which - so their documentation - indicates that the name-parameter is missing. I've opened the API as URL in my browser and attached both parameters as GET, to check if it is a fault in the API, but when sending it as GET in the browser, I get the requested result as expected. I tried to change my code to send a get instead of a post call (I've called "get" instead of "post", I hope that's correct. I haven't been able to locate the corresponding class), but as soon as I do, I get a 'wrong secret' error, probably because it doesn't recognize any parameters at all. Any ideas where I'm going wrong?
 
Back
Top Bottom