1

我正在练习使用flutter的http插件发出一些get请求,当我向[https://www.pexels.com]发出请求时,我得到403 Status Code。但是当我用 chrome 浏览器打开目标 URL 时它工作正常。

是否可以使用一些标题来解决?如果是这样,如何?

这是我的代码:

    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);
    }

状态码:I/flutter (28151): 403

响应头: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}

来自 Google Chrome 浏览器的请求标头: 在此处输入图像描述

4

0 回答 0