Thank you for your quickly reply.
I tried, but it didn't work, still the same issue.
Pls kindly check my codes as followings:
File attachFile = new File("D:/test.xlsx");
respMsg = createAttachmentByTaskId(taskId, attachFile, userName, password);
FileBody fb = new FileBody(attachFile);
HttpResponse resp = JsonRequest.multipartRequest(url, fb, true, userName, password);
public static HttpResponse multipartRequest(String url, FileBody fb, boolean auth, String userName, String password)
throws Exception {
HttpResponse resp = null;
JSONObject returnResult = null;
DefaultHttpClient client = new DefaultHttpClient();
try {
HttpPost httppost = new HttpPost(url);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("file", fb);
reqEntity.addPart("name", new StringBody("test.xlsx"));
httppost.setEntity(reqEntity);
logger.info("post: " + url);
if (auth) {
client.getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM),
new UsernamePasswordCredentials(userName, password));
AuthCache authCache = new BasicAuthCache();
BasicScheme basicAuth = new BasicScheme();
String restServerAddr = PropertiesUtil.getProperty("activiti.rest.server.address");
int restServerPort = StringUtil.getInt(PropertiesUtil.getProperty("activiti.rest.server.port"));
authCache.put(new HttpHost(restServerAddr, restServerPort, "http"), basicAuth);
BasicHttpContext localcontext = new BasicHttpContext();
localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);
httppost.addHeader(HTTP.CONTENT_TYPE, "multipart/form-data; boundary=—————————28617237579832");
resp = client.execute(httppost, localcontext);
} else {
resp = client.execute(httppost);
}
return resp;
} catch (Exception e) {
logger.error("multipartRequest for [" + url + "] error: " + e.getMessage(), e);
} finally {
try {
client.getConnectionManager().shutdown();
} catch (Exception ignore) {
}
}
return resp;
}