私の質問を見てくれてありがとう:)
ゲーム「Ace of Spades」を起動するプログラムを作成しています。現時点でゲームをプレイする唯一の方法は、ブラウザでゲームの Web サイトを開き、適切なサーバーを検索して、クリックするまでに満杯にならないようにすることです。そのため、これらのサーバーを整理するためのランチャーを作成することは、楽しくて便利なプロジェクトになると考えました。
ただし、修正方法がわからないという奇妙なエラーが発生しました:「java.io.IOException: Server reutrned HTTP response code: 403 for URL: http://www.ace-spades.com/play /」。
私のブラウザの設定では、ほとんどのウェブサイト (「https://google.com」を含む) は問題なく読み込まれますが、何らかの理由で、エース オブ スペードのウェブサイトがそれを拒否しています! これはタイプミスではなく、ウェブサイトがダウンしていたりもしていません (Google Chrome では問題なく読み込まれます)。したがって、DDoS 攻撃などを回避するための安全プロトコルとしてアクセスを拒否しているに違いないと思います。そのため、Chrome で問題なく動作する場合、ブラウザで Chrome (または他の一般的なブラウザ) を特定の点でエミュレートすることで、この問題が解決する可能性があると思います。または、プログラムで愚かで愚かなことをしているだけかもしれません (私は Java の初心者です)。手伝って頂けますか?
これが私のプログラムです:
//*****ADD-ONS*****
package browser;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import java.net.*;
import java.io.*;
//*****PROGRAM*****
public class MainClass{
//Initialize general variables
private JFrame frame;
private JPanel panelTop;
private JEditorPane editor;
private JScrollPane scroll;
private JTextField field;
private JButton button;
private URL url;
private String windowTitle = "Ace of Spades Launcher";
private String homePage = "http://www.ace-spades.com/play/"; //"https://google.com";
private int screenWidth = 854;
private int screenHeight = 480;
//MainClass CONSTRUCTOR
public MainClass(){
//Initialize Components
initComponents();
//Set up frame
frame.setTitle(windowTitle);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(screenWidth,screenHeight);
frame.setLocationRelativeTo(null);
frame.add(BorderLayout.NORTH,panelTop); //Add JPanel to north of JFrame
panelTop.add(field); //Add TextField to JPanel
panelTop.add(button); //Add "Go" button to JPanel
frame.add(BorderLayout.CENTER,scroll); //Add scroll pane to JFrame
frame.setVisible(true);
}
//COMPONENT INITIALIZER
private void initComponents(){
frame = new JFrame(); //Create the JFrame
panelTop = new JPanel(); //Create the JPanel used to hold the text field and button
try{ //Set the URL
url = new URL(homePage);
}catch(MalformedURLException mue){
JOptionPane.showMessageDialog(null,mue);}
try{ //Create the JEditorPane
editor = new JEditorPane(url);
editor.setEditable(false); //Set the editor pane to false
}catch(IOException ioe){
JOptionPane.showMessageDialog(null,ioe);}
scroll = new JScrollPane( //Create the scroll pane and add the JEditorPane to it
editor,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
);
field = new JTextField(); //Create the JTextField
/**NOTE: We're not doing this on the event dispatch thread, so we need to use SwingUtilities */
SwingUtilities.invokeLater( //Set the JTextField text to the URL
new Runnable(){
public void run(){
field.setText(url.toString());
}
}
);
button = new JButton("Go"); //Create the button for changing pages.
button.addActionListener( //Add action listener to the button
new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
editor.setPage(field.getText());
}catch(IOException ioe){
JOptionPane.showMessageDialog(null,ioe);}
}
}
);
editor.addHyperlinkListener( //Enable hyperlink clicking
new HyperlinkListener(){
public void hyperlinkUpdate(HyperlinkEvent e){
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED){
try{
editor.setPage(e.getURL());
}catch(IOException ioe){
JOptionPane.showMessageDialog(null,ioe);}
}
}
}
);
}
//MAIN PROGRAM EXECUTER
public static void main(String[] args) {
SwingUtilities.invokeLater(
new Runnable(){
public void run(){
new MainClass();}
}
);
}
}