0
私は数時間、個人用ページでビューを生成しようとしています。私はなぜそれが働いていないのか分からない。だから私の現在のコード:(はい、スピゴット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全体に適用されます。別のスレッドで異なる値を設定していませんか? –
プロジェクト全体で唯一のことはありません。 –