curlrequest not updating the headers |
Hi,
It seems that the "curlrequest" is not updating the header when I make 2 API calls right after another. One API call to get the token (with 2 header items) then again call the second API with the Token in the header (3 header items). Second API call keeps failing as the header is not getting updated. To test this I got the Token from the 1st and Hard corded it to the second and disable the 1st call, then it worked. $client = \Config\Services::curlrequest(); $body = '{"username":"[email protected]","password" : "'.$keys->pw.'"}'; /// 1st call $result = $client->setBody($body)->post($keys->url.'/v1/login/', [ 'headers' => [ 'Content-Type' => 'application/json', 'x-api-key' => $keys->key ] ]); $info = json_decode($result->getBody()); ///2nd call $result2 = $client->get($keys->url.'/v1/members/data/'.$member_id, [ 'headers' => [ 'Content-Type' => 'application/json', 'Authorization' => 'JWT '.$info->token, 'x-api-key' => $keys->key ], 'debug' => true, 'http_errors' => false ]); Please help!
Found the problem.
\Config\Services::curlrequest() instant is shared, so it want get updated. Can some one please tell me how to pass false on this so it will load a new instance on the second round.
Found the solution to my problem.
Any body else facing this load the service as below. $client = \Config\Services::curlrequest(array(),null,null,false);
Personally I would create it without the service, I think it's cleaner.
Code: $options = []; // optional.
You can also use `single_service()` so that you're assured that the resulting object is always a fresh instance.
|
Welcome Guest, Not a member yet? Register Sign In |