所以即时尝试在个人页面上生成视图几个小时了。我不知道为什么它不起作用。所以我现在的代码:(是的,我使用的是spigot API,但现在没关系)。
@Override
public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
if(args.length == 2){
String link = args[0];
String views = args[1];
int view = 0;
try{
view = Integer.parseInt(views);
}catch(Exception ex){
ex.printStackTrace();
cs.sendMessage("" + views + " is not a number.");
}
execute(link, view);
}else{
System.out.println("More arguments");
}
return true;
}
private int o = 1;
private void execute(String link, int views){
new BukkitRunnable() {
int i = views;
@Override
public void run() {
i--;
try{
String fullProxy = Viewbot.getInstance().getProxys().get(i);
String proxy, port;
String[] fullProx;
fullProx = fullProxy.split(":");
proxy = fullProx[0];
port = fullProx[1];
/* Proxy proxyCon = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy, Integer.parseInt(port)));
HttpURLConnection connection =(HttpURLConnection)new URL(link).openConnection(proxyCon);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Content-type", "text/xml");
connection.setRequestProperty("Accept", "text/xml, application/xml");
connection.setRequestMethod("POST");
*/
Properties systemProperties = System.getProperties();
systemProperties.setProperty("http.proxyHost",proxy);
systemProperties.setProperty("http.proxyPort",port);
systemProperties.setProperty("https.proxyHost",proxy);
systemProperties.setProperty("https.proxyPort",port);
URL server = new URL(link);
HttpURLConnection connection = (HttpURLConnection)server.openConnection();
connection.setUseCaches(false);
connection.connect();
System.out.println("Respone: "+ connection.getResponseMessage());
System.out.println("View #" + o + " gesendet!");
o++;
connection.disconnect();
System.out.println("Proxy: " + proxy + " Port: " + port);
System.out.println("System using: " + systemProperties.getProperty("http.proxyHost") + ":" + systemProperties.getProperty("http.proxyPort"));
System.out.println("Proxy: " + connection.usingProxy());
}catch(Exception ex){
Properties systemProperties = System.getProperties();
ex.printStackTrace();
Viewbot.getInstance().failProxys.add(systemProperties.getProperty("http.proxyHost") + ":" + systemProperties.getProperty("http.proxyPort"));
}
if(i == 5){
for(int i = 0; i < Viewbot.getInstance().failProxys.size(); i++){
String failed = Viewbot.getInstance().failProxys.get(i);
Viewbot.getInstance().getProxys().remove(failed);
}
Path file = Paths.get(Viewbot.getInstance().getDataFolder() + "/HTTPS.txt");
try {
Files.write(file, Viewbot.getInstance().getProxys(), Charset.forName("UTF-8"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("File saved");
}
if(i == 0){
cancel();
}
}
}.runTaskTimerAsynchronously(Viewbot.getInstance(), 0, 2);
}
整件事的样本输出:
[00:34:45 INFO]: Response: OK
[00:34:45 INFO]: View #430 sent!
[00:34:45 INFO]: Proxy: 41.76.44.76 Port: 3128
[00:34:45 INFO]: System using: 45.63.16.86:8080
[00:34:45 INFO]: Proxy: false
现在的输出是:
[00:57:58 INFO]: Proxy: 36.80.34.225 Port: 3128
[00:57:58 INFO]: System using: 113.18.193.26:8000
[00:57:58 INFO]: Proxy: true
[00:57:58 INFO]: Respone: OK
但是当你看到这里时:http://84.200.122.107/它不会添加视图..
因此它使用不同的IP地址进行连接。什么是错误? 它还表明它没有使用代理,这应该是错误的.. 谢谢你的帮助。
答案 0 :(得分:0)
我认为你遍历代理列表,每次调用BukkitRunnable都会有一个新的。
因此,如果在不同线程中调用BukkitRunnable重叠,则设置值,另一个读取它。
要为每个连接使用一个代理,您应该使用能够执行此操作的公共http客户端: