Welcome Guest, Not a member yet? Register   Sign In
How can get Response from API when status is 4xx using Curl library
#3

(06-06-2024, 08:55 PM)kenjis Wrote: Are you talking about CURLRequest?
See https://codeigniter.com/user_guide/libra...ttp-errors

yes, its about it.
but how to get response from API when its status code is 400, 401

I use try-catch, but in catch cant use like Guzzle

PHP Code:
try {
    $response $client->request('GET''http://example.com/api-endpoint');
    echo $response->getBody();
} catch (
RequestException $e) {
    // check response if fail cause some reason
    if ($e->hasResponse()) {
        $response $e->getResponse();
        echo 'HTTP Status Code: ' $response->getStatusCode() . "\n";
        echo 'Response Body: ' $response->getBody();
    } else {
        echo 'Request exception occurred without a response';
    }

Reply


Messages In This Thread
RE: How can get Response from API when status is 4xx using Curl library - by mylastof - 06-07-2024, 01:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB