Welcome Guest, Not a member yet? Register   Sign In
curlrequest - help

(This post was last modified: 08-15-2021, 11:36 PM by chakycool.)


I'm trying to call a REST API using the curlrequest service and I think I go the post syntax wrong. Can someone help me.

PHP Code:
$client single_service('curlrequest');
$result $client->post($keys->url.'/v2/', [
                    'headers' => [
                              'Content-Type' => 'application/json',
                                'Authorization' => 'JWT '.$access->token,
                                'x-api-key'    => $keys->key
                    'body' => $payload,
                    'debug' => true              

This syntax is not posting the body payload, everything else is fine.

From looking at the service code your missing the options array when getting the service. that's where the base_uri is setup.

Look at the code in system/Config/Services.php
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

I'm not defining the base_uri but passing the full URL. Below is the updated code.

$keys->url = "https://dommain.com"
$client = single_service('curlrequest');
$result = $client->post($keys->url.'/v2/', [
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'JWT '.$access->token,
'x-api-key' => $keys->key
'body' => $payload,
'debug' => true

I tried the below method and it worked.

Looks like we can't pass the body payload in the option array.

Theme © iAndrew 2016 - Forum software by © MyBB