用Java调用API batchDownloadFile以取得文件下载的URL,
JSONObject jsonObject = null;
CloseableHttpClient client = HttpClients.createDefault();
CloseableHttpResponse response = null;
StringEntity entity = null;
try{
HttpPost post = new HttpPost(url);
JSONObject jsonParam = new JSONObject();
String p = "\"env\": \"testabc\",\"file_list\":[{\"max_age\":7200,\"fileid\":\"cloud://testabc.6465-testabc-1301363499/uploadFile/1593934426186-99.png\\\"}]";
entity = new StringEntity(p,"utf-8");
post.setEntity(entity);
post.setHeader(new BasicHeader("Content-Type", "application/json; charset=utf-8"));
post.setHeader(new BasicHeader("Accept", "application/json;charset=utf-8"));
response = client.execute(post);
int statusCode = response.getStatusLine().getStatusCode();
if (SUCCESS_CODE == statusCode){
String result = EntityUtils.toString(response.getEntity(),"UTF-8");
try{
jsonObject = JSONObject.parseObject(result);
return jsonObject;
}catch (Exception e){
return result;
}
}else{
LOGGER.error("POST请求失败!");
}
}catch (Exception e){
LOGGER.error(e);
}finally {
response.close();
client.close();
}
return null;
但是这样写却是得到错误 {"errcode":47001,"errmsg":"data format error hint: [LiedKowFE-CrZvia]"}
这个代码去请求token,完全可以。用相同的file_list数据从postman去请求,完全可以得到文件下载列表,但怎么代码里就返回错误呢?
比较怀疑file_list这块,试过把/改成\/,"成\",但是都是相同错误。不知道到底是什么问题了。
这是json?
原本是
JSONObject jsonParam = new JSONObject();
jsonParam.put(“env“, envID);
jsonParam.put("file_list", fileArray);
entity = new StringEntity(jsonParam.toString(),"utf-8");