так что я пытаюсь генерировать Views на личной странице в течение нескольких часов. Я не понимаю, почему он не работает. Итак, мой текущий код: (Да, я использую API-интерфейс, но это не имеет значения сейчас).Java - Создание представлений с Proxys
@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-адрес для подключения. Какая ошибка? Он также показывает, что он не использует прокси-сервер, который должен быть неправильным. Спасибо за любую помощь.
systemProperties.setProperty ("http.proxyHost", прокси); является JVM-wide. У вас нет другого потока, устанавливающего разные значения? –
У меня нет единственного во всем проекте. –