【问题标题】:How to download files from a third party Rest end point in Java [duplicate]如何从Java中的第三方Rest端点下载文件[重复]
【发布时间】:2020-05-04 15:59:03
【问题描述】:

我想在 java 中从第三方 rest 端点下载文件

google 提供的示例 CURL,它按预期工作,但我想用 java 设计它。 我尝试用谷歌搜索,但无法获得帮助。

请求方法是“GET”和多部分 HTTP 请求

curl -L -O -k -u 'username:password' -X GET http://localhost:8080/secure/attachment/1461863/fileName.txt

任何示例代码或链接都可以。

谢谢

【问题讨论】:

标签: java spring-boot rest java-8 jira-rest-api


【解决方案1】:

如果您不想使用 jdk 以外的其他依赖项,则可以使用以下内容:

URL url = new URL("http://localhost:8080/secure/attachment/1461863/fileName.txt");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("GET");

    if (conn.getResponseCode() != 200) {
        throw new RuntimeException("Failed : HTTP error code : "
                + conn.getResponseCode());
    }

【讨论】:

    猜你喜欢
    • 2015-01-27
    • 2016-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多