main
黄海 7 months ago
parent cf539f7608
commit 9f84aaa89b

@ -14,13 +14,19 @@ public class UploadMaxKBFile {
private static final String baseUrl = "http://10.10.14.206:8080";
private static final String Authorization_URL = baseUrl + "/api/user/login";
/**
* maxkb api
* https://bbs.fit2cloud.com/t/topic/5446/3
*/
//知识库上传文档接口地址 知识库id不知道id的可以从知识库的地址栏获取
static String zskId = "409225d8-c352-11ef-a419-0242ac120003";
static String zskId = "0dbf473a-c352-11ef-a5a3-0242ac120003";
//知识库url上传地址
static String qaUrl = baseUrl + "/api/dataset/" + zskId + "/document/qa";
static String testUrl = baseUrl + "/api/dataset/" + zskId + "/document/_bach";
//获取身份识别时登录的用户名
private static final String username = "admin";
//获取身份识别时登录的密码
@ -29,23 +35,19 @@ public class UploadMaxKBFile {
public static void main(String[] args) throws Exception {
//获取身份识别
String authCode = getAuthorization(username, password);
System.out.println("Authorization_CODE:" + authCode);
//写死从浏览器抄出来的authCode
authCode="eyJ1c2VybmFtZSI6ImFkbWluIiwiaWQiOiJmMGRkOGY3MS1lNGVlLTExZWUtOGM4NC1hOGExNTk1ODAxYWIiLCJlbWFpbCI6IiIsInR5cGUiOiJVU0VSIn0:1tQe5R:ciXGy3HMQx-GYYZdV5a-zl8pFBrszW3IsKzZ-lUL_gw";
System.out.println("Authorization_CODE:" + authCode);
//获取知识库上传文档接口
String uploadFile = "D:\\dsWork\\QingLong\\Doc\\MaxKB\\各学校人员和班级统计【结果】.xlsx";
//使用hutool工具箱里面的httpPost功能向指定的接口发起上传文件的请求在Header中携带参数authCode
HttpResponse response = HttpRequest.post(qaUrl)
.header("Accept", "application/json, text/plain, */*")
.header("Accept-Encoding","gzip,deflate")
.header("Accept-Language","zh-CN,zh;q=0.9")
.header("Accept-Encoding", "gzip,deflate")
.header("Accept-Language", "zh-CN,zh;q=0.9")
.header("Authorization", authCode)// 添加header
.header("Connection", "keep-alive")
.header("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundaryhEiEDpZDka6byweA")
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36")
.header("Referer", "http://10.10.14.206:8080/ui/dataset/upload?id=0dbf473a-c352-11ef-a5a3-0242ac120003")
.form("file", new File(uploadFile)).execute();// 添加文件
// 获取响应状态码
@ -78,6 +80,7 @@ public class UploadMaxKBFile {
.timeout(10000) // 可选:设置超时时间(毫秒)
.execute();
System.out.println(response);
// 详细的状态处理
if (response.isOk()) {
String body = response.body();

Loading…
Cancel
Save