Flutter http get() 403 status code problem

947 views Asked by At

I'm practicing on making some get requests using flutter's http plugin, and when I make a request to [https://www.pexels.com], I get 403 Status Code. But when I open the target Url with chrome browser It works fine.

Is it something that can be solved using some headers?? If so, How??

Here is my Code:

    void getData() async {
        Response response = await get(Uri.encodeFull('https://www.pexels.com'));
        if (response.statusCode == 200) {
          print('connected');
        } else {
          print('connection error');
        }
        print(response.statusCode);
        print(response.headers);
    }

Status Code: I/flutter (28151): 403

response.headers:I/flutter (28151): {connection: close, cache-control: private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0, set-cookie: __cfduid=d22dd51645467ea70238107d1e15f9a2d1607634921; expires=Sat, 09-Jan-21 21:15:21 GMT; path=/; domain=.pexels.com; HttpOnly; SameSite=Lax,__cf_bm=d4c93b1eb4dd2f86fe359617a86f82ba9c90e0d0-1607634921-1800-Ae/p5j0v/53c10n4CBxIlK2mTPDdau3ZpYqbReQLNVrOEyX6pjZBZ6RU0TWU8mxnL4MfxpFfNiLeHkgAlCjwzJY=; path=/; expires=Thu, 10-Dec-20 21:45:21 GMT; domain=.pexels.com; HttpOnly; Secure; SameSite=None, transfer-encoding: chunked, date: Thu, 10 Dec 2020 21:15:21 GMT, cf-request-id: 06f01b415e0000af9c2d97d000000001, content-encoding: gzip, vary: Accept-Encoding, content-type: text/html; charset=UTF-8, expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct", server: cloudflare, cf-ray: 5ff9fb156d4baf9c-BGW, cf-chl-bypass: 1, x-frame-options: SAMEORIGIN, expires: Thu, 01 Jan 1970 00:00:01 GMT}

Request headers from Google Chrome Browser: enter image description here

0

There are 0 answers