由于Cloudflare无法从网址读取数据 [英] Can't read data from url due to cloudflare
问题描述
每次编译时,我都会得到:
Whenever I compile, i get this:
线程 main中的异常java.io.IOException:服务器返回了HTTP
响应代码:URL的403:位于
sun.net.www.protocol.http.HttpURLConnection.getInputStream0(未知
源)处的链接,位于
sun.net.www.protocol。位于java.net的http.HttpURLConnection.getInputStream(未知
源)位于
的URL.openStream(未知源)readdata.aaa.main(aaa.java:15)
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读取数据?
Is there anyway I can bypass the cloudflare in order to read the data from the URL ?
推荐答案
之前
URL oracle = new URL(" the link ");
插入:
System.setProperty("http.agent", "Chrome");
这可能是因为CloudFlare阻止了未知的代理请求,因此此代码将User-Agent设置为Chrome被CloudFlare认可。
That's probably because CloudFlare prevent from unknown agent requests so this code set the User-Agent to Chrome who is recognized by CloudFlare.
这篇关于由于Cloudflare无法从网址读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!