|
发表于 2023-6-20 09:29:23
|
显示全部楼层
首先感谢您的回复是的这段代码已经改成了下面这段代码,传入方法的fileNames和fileIDs确实是空数组,我现在在测试接口是否可以连接.可是这段代码是有执行成功的但并没有向接口发送请求
function sendRequest(fileNames, fileIDs, pathName){
try{
print("发起请求:");
var url = 'http://localhost:9002/OAfile/download';
var ArrayList = Java.type('java.util.ArrayList');
var heads = new ArrayList();
var NameValuePair = Java.type('com.x.base.core.project.bean.NameValuePair');
var p1 = new NameValuePair('Content-Type', 'application/json');
heads.add(p1);
var HttpConnectionClass = Java.type('com.x.base.core.project.connection.HttpConnection');
// 创建一个JSON对象,包含三个参数
var data = {
"fileNames": fileNames,
"fileIDs": fileIDs,
"Path": pathName
};
// 将JSON对象转换为字符串
var json = JSON.stringify(data);
// 发送POST请求
var resp = HttpConnectionClass.postAsString(url, heads, json);
print( "返回:"+ resp.toString());
}catch(e){
print("发送请求出错:");
print( e.printStackTrace() );
}
}
// 定义文件名和文件ID的数组
var attachmentList = this.workContext.getAttachmentList();
var fileNames = [];
var fileIDs = [];
var pathName = '薪资调整';
// 调用sendRequest函数,发送POST请求
sendRequest(fileNames, fileIDs, pathName); |
|