url - 由于 cloudflare,无法从 url 读取数据

标签 url cloudflare

每当我编译时,我都会得到这个:

Exception in thread "main" java.io.IOException: Server returned HTTP response code: 403 for URL: the link at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) at java.net.URL.openStream(Unknown Source) at readdata.aaa.main(aaa.java:15)

我的脚本是:

package readdata;

import java.net.*;
import java.io.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class aaa 
{
    public static void main(String[] args) throws Exception {

        URL oracle = new URL(" the link ");
        BufferedReader in = new BufferedReader(
        new InputStreamReader(oracle.openStream()));

        String inputLine;
        StringBuilder a = new StringBuilder();
        while ((inputLine = in.readLine()) != null)
            a.append(inputLine);
        in.close();


        int i = 0;
        Pattern p = Pattern.compile("Open");
        Matcher m = p.matcher( a );
        while (m.find()) {
            i++;
            System.out.println(i);
        }
    }

}

无论如何我可以绕过 cloudflare 以便从 URL 读取数据吗?

最佳答案

之前

URL oracle = new URL(" the link ");

插入:

System.setProperty("http.agent", "Chrome");

这可能是因为 CloudFlare 阻止了未知代理请求,因此此代码将 User-Agent 设置为 CloudFlare 识别的 Chrome。

关于url - 由于 cloudflare,无法从 url 读取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57602991/

相关文章:

magento - 当我有唯一的 URL 参数时,如何让 Magento 提供页面的缓存版本?

MYSQL - 在托管未知 URL 时我应该选择哪种变量类型?

java - 未报告的异常 IOException 从 URL 读取文件

javascript - 页面加载时的 HtmlUnit JavaScript 问题 - 找不到函数

javascript - 我想让用户输入更改链接

java - JEdi​​torPane 的奇怪行为

ssl - ASP.Net 网站上的 CloudFlare Flexible SSL Redirect Loop

security - CloudFlare "Flexible SSL"不如 "Off"安全?

ssl - Shopify SSL 不适用于 CloudFlare?

kubernetes - 在具有固定域和端口的 GKE 中运行可扩展服务