|
|
|
@ -13,10 +13,7 @@ public class UploadMaxKBFile {
|
|
|
|
|
//获取身份识别码接口
|
|
|
|
|
private static final String baseUrl = "http://10.10.14.206:8080";
|
|
|
|
|
private static final String Authorization_URL = baseUrl + "/api/user/login";
|
|
|
|
|
//获取身份识别时登录的用户名
|
|
|
|
|
private static final String Authorization_USERNAME = "admin";
|
|
|
|
|
//获取身份识别时登录的密码
|
|
|
|
|
private static final String Authorization_PASSWORD = "Dsideal4r5t6y7u!@#";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//知识库上传文档接口地址 知识库id,不知道id的可以从知识库的地址栏获取
|
|
|
|
|
static String zskId = "409225d8-c352-11ef-a419-0242ac120003";
|
|
|
|
@ -24,19 +21,28 @@ public class UploadMaxKBFile {
|
|
|
|
|
//知识库url上传地址
|
|
|
|
|
static String qaUrl = baseUrl + "/api/dataset/" + zskId + "/document/qa";
|
|
|
|
|
|
|
|
|
|
//获取身份识别时登录的用户名
|
|
|
|
|
private static final String username = "admin";
|
|
|
|
|
//获取身份识别时登录的密码
|
|
|
|
|
private static final String password = "Dsideal4r5t6y7u!@#";
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
|
//获取身份识别
|
|
|
|
|
String authCode = getAuthorization(Authorization_USERNAME, Authorization_PASSWORD);
|
|
|
|
|
String authCode = getAuthorization(username, password);
|
|
|
|
|
System.out.println("Authorization_CODE:" + authCode);
|
|
|
|
|
|
|
|
|
|
//获取知识库上传文档接口
|
|
|
|
|
String uploadFile = "D:\\dsWork\\QingLong\\Doc\\MaxKB\\各学校人员和班级统计【结果】.xlsx";
|
|
|
|
|
//使用hutool工具箱里面的httpPost功能,向指定的接口发起上传文件的请求,在Header中携带参数authCode
|
|
|
|
|
HttpResponse response = HttpRequest.post(qaUrl)
|
|
|
|
|
// 添加header
|
|
|
|
|
.header("Authorization_CODE", authCode)
|
|
|
|
|
// 添加文件
|
|
|
|
|
.form("file", new File(uploadFile))
|
|
|
|
|
.execute();
|
|
|
|
|
.header("Accept", "application/json, text/plain, */*")
|
|
|
|
|
.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")
|
|
|
|
|
.form("file", new File(uploadFile)).execute();// 添加文件
|
|
|
|
|
|
|
|
|
|
// 获取响应状态码
|
|
|
|
|
int status = response.getStatus();
|
|
|
|
|