Commit a817d8c0 authored by wdy's avatar wdy

调用接口

parent c783e662
package com.ruoyi;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
public class TestDownload {
@Test
public void test() {
try {
// 直接使用URL作为POST请求的目标,假设所有需要的信息已包含在URL中
HttpResponse response = HttpRequest.post("https://10.12.48.78:8090/api/project/download" + "/fd40de37-9c57-4597-8f74-d0754dfa17b2")
// 如果需要添加特定的请求头,如认证信息,可以在这里添加
//.header("Authorization", "Bearer your_token_here")
.execute();
// 检查响应是否成功
if (response.isOk()) {
System.out.println("response = " + response);
// 获取文件名,这里简化处理,实际情况可能需要从响应头中解析(如Content-Disposition)
// String fileName = "downloaded_file_from_post.zip";
//
// // 保存到本地
// FileUtil.writeBytes(IoUtil.readBytes(response.bodyStream()), FileUtil.file(fileName));
//
// System.out.println("文件下载成功:" + fileName);
} else {
System.err.println("下载失败,状态码:" + response.getStatus());
}
} catch (Exception e) {
e.printStackTrace();
}
//以post形式请求接口
// String result= HttpUtil.post("https://10.12.48.78:8090/api/project/download","/fd40de37-9c57-4597-8f74-d0754dfa17b2");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment