Welcome Guest, Not a member yet? Register   Sign In
Error in using CURLRequest Class in case of GET type request
#5

(This post was last modified: 10-12-2022, 04:35 PM by kenjis.)

Code:
$ curl https://api.github.com/user -i
HTTP/2 401
server: GitHub.com
date: Wed, 12 Oct 2022 23:18:01 GMT
content-type: application/json; charset=utf-8
content-length: 131
x-github-media-type: github.v3; format=json
access-control-expose-headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
access-control-allow-origin: *
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'
vary: Accept-Encoding, Accept, X-Requested-With
x-ratelimit-limit: 60
x-ratelimit-remaining: 48
x-ratelimit-reset: 1665619900
x-ratelimit-resource: core
x-ratelimit-used: 12
x-github-request-id: EF15:68C0:4A7D3:680E7:63474B37

{"message":"Requires authentication","documentation_url":"https://docs.github.com/rest/reference/users#get-the-authenticated-user"}

Quote:By default, CURLRequest will fail if the HTTP code returned is greater than or equal to 400. You can set http_errors to false to return the content instead:
https://codeigniter4.github.io/CodeIgnit...ttp-errors

PHP Code:
        $client  = \Config\Services::curlrequest();
        $response $client->request(
            'GET',
            'https://api.github.com/user',
            [
                'headers' => [
                    'User-Agent' => 'datamweb/1.0',
                ],
                'http_errors' => false,
            ]
        );

        return $response->getStatusCode()."\n".$response->getBody(); 

I see
Code:
401
{"message":"Requires authentication","documentation_url":"https://docs.github.com/rest/reference/users#get-the-authenticated-user"}

If I removed Usesr-Agent, I got this:
Quote:Request forbidden by administrative rules. Please make sure your request has a User-Agent header (https://docs.github.com/en/rest/overview...t-required). Check https://developer.github.com for other possible causes.

It seems I cannot reproduce the OpenSSL error:
Code:
OpenSSL SSL_connect: Connection was reset in connection to api.github.com:443
Reply


Messages In This Thread
RE: Error in using CURLRequest Class in case of GET type request - by kenjis - 10-12-2022, 04:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB