java - 尝试从我的网络服务器下载 exe 时出现 403 错误

标签 java apache http web

我不断收到 403 错误,我尝试了一切方法来使其适合我正在制作的自动更新程序,该更新程序应该获得 .exe 并用新更新的 .exe 替换旧的 .exe...

package cyara;

import javafx.event.ActionEvent;
import javafx.scene.control.Label;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;

public class Controller {
    public Label latest;
    public Label verision;
    private String version = "1.0";

    public void downloadLatest(ActionEvent actionEvent) {
        verision.setText("Current Updater Version " + version);
        latest.setText("Downloading Files");

        String url = "https://www.kadepcgames.com/downloads/cyara/b-0001/latest/Cyara.exe";

        try {
            latest.setText("Connecting to www.kadepcgames.com/downloads/cyara/b-0001/latest/Cyara.exe");
            downloadUsingNIO(url, "/Program Files/Cyara/Cyara.exe");
            latest.setText("Trying to download the backup");
            downloadUsingStream(url, "/Program Files/Cyara/CyaraBackup.exe");
        } catch (IOException e) {
            latest.setText("Download Failed!");
            e.printStackTrace();
        }
    }

    private static void downloadUsingStream(String urlStr, String file) throws IOException {
        URL url = new URL(urlStr);
        URLConnection uc;
        uc = url.openConnection();
        uc.addRequestProperty("User-Agent",
                        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
        BufferedInputStream bis = new BufferedInputStream(url.openStream());
        FileOutputStream fis = new FileOutputStream(file);
        byte[] buffer = new byte[1024];
        int count = 0;
        while ((count = bis.read(buffer,0,1024)) != -1) {
            fis.write(buffer, 0, count);
        }
        fis.close();
        bis.close();
    }

    private static void downloadUsingNIO(String urlStr, String file) throws IOException {
        URL url = new URL(urlStr);
        URLConnection uc;
        uc = url.openConnection();
        uc.addRequestProperty("User-Agent",
                        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
        ReadableByteChannel rbc = Channels.newChannel(url.openStream());
        FileOutputStream fos = new FileOutputStream(file);
        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
        fos.close();
        rbc.close();
    }

}

我得到了 java.io.IOException: Server returned HTTP response code: 403 for URL: https://www.example.com/downloads/cyara/b-0001/latest/Cyara.exe错误 大多数尝试过教程,但没有一个对我有用。所以我唯一想到的就是权限(我检查过),即使将它们设置为 777 仍然没有运气! 我真的厌倦了这个。

最佳答案

我建议检查apache配置。由于 .exe 扩展名,apache 可能会阻止该请求。

看看这篇文章: 403 error on .exe files apache

关于java - 尝试从我的网络服务器下载 exe 时出现 403 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49330478/

相关文章:

php - 从 PHP 将 Http 状态代码返回给 Apache?

java - 如何通过反射但使用依赖注入(inject)创建对象?

java - 当用户单击 WebView 内的链接时如何给出 url

java - ubuntu 14.04 上的 apache hama 安装错误

php - .php 文件下载而不是执行

http - 将(原始)请求从 GET 转换为 POST

具有已定义超时的 Java HTTP 客户端请求

java - 如何在时间序列jfree图表上添加文本/图像

java - TextInputLayout - 动态设置 float 文本颜色

regex - htaccess - 如何比较环境变量 - 检查 2 个环境变量是否相同