자카르타 Commons HttpClient 3. x 파일 업로드
2559 단어 CommonsHttpClientHTTP
이 방식 을 사용 하려 면 comons - httpclient - 3.1. jar 를 가 져 와 야 합 니 다. httpmime - 4.1.3. jar 와 comons - codec - 1.3. jar
이런 종류의 가방 들 은 나의 자원 에서 찾 을 수 있다.
단일 파일 업로드:
try {
HttpClient httpclient = new DefaultHttpClient();
//
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httppost = new HttpPost(url);
MultipartEntity mpEntity = new MultipartEntity(); //
mpEntity.addPart("", new FileBody(file));
mpEntity.addPart("",new StringBody(""));
httppost.setEntity(mpEntity);
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
Message msg = new Message();
signTime = ParseXmlUtils.signTime(resEntity.getContent());
resEntity.consumeContent();
}
resEntity.consumeContent();
httpclient.getConnectionManager().shutdown();
} catch (Exception e) {
e.printStackTrace();
file.delete();
}
다 중 파일 업로드:
for(File file:files){
PostMethod filePost = new PostMethod("this is url");
try {
String fileName ="filename";
// post
Part[] parts = { new StringPart("userId", "userId"),
new StringPart("fileName", URLEncoder.encode(URLEncoder.encode(fileName, "utf-8"), "utf-8")),
new FilePart("file", file),
};
filePost.setRequestEntity(new MultipartRequestEntity(parts,filePost.getParams()));
HttpClient client = new HttpClient();
client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
// post
client.executeMethod(filePost);
} catch (Exception e) {
e.printStackTrace();
} finally {
filePost.releaseConnection();
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Firestore 컬렉션의 모든 데이터 수를 얻는 방법페이지 네이션에 필요한, Firestore 컬렉션의 모든 데이터 건수 취득. 데이터 크기에 따라 획득 방법을 변경하는 것이 좋습니다 (성능에 영향). 아래에 방법. 데이터를 로컬로 로드하고 카운트합니다. 그리고 이 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.