感谢您查看我的问题:)
我正在为我制作一个程序来启动游戏“黑桃 A”。现在玩游戏的唯一方法是在浏览器中打开游戏网站,搜索一个好的服务器,然后希望在您点击它时它还没有满员。所以我认为制作一个启动器来为我组织这些服务器将是一个有趣且有用的项目。
但是,我遇到了一个奇怪的错误,我不确定如何修复:“java.io.IOException:服务器重新发送 HTTP 响应代码:403 for URL:http ://www.ace-spades.com/play / "。
我的浏览器设置可以很好地加载大多数网站(包括“https://google.com”),但由于某种原因黑桃王牌网站拒绝了它!这不是一个错字,网站没有关闭或任何东西(它在谷歌浏览器中加载得很好),所以我认为它必须拒绝访问作为一种安全协议,以避免 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();}
}
);
}
}