Created
August 22, 2011 06:09
-
-
Save mryoshio/1161766 to your computer and use it in GitHub Desktop.
build POST request which has multipart body (String and Image)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private HttpPost buildPostRequest(String _method, String _path, Map _params) | |
throws ServerConnectionException { | |
HttpPost request = new HttpPost(); | |
try { | |
request.setURI(URIUtils.createURI(scheme, host, port, _path, null, | |
null)); | |
MultipartEntity entity = new MultipartEntity( | |
HttpMultipartMode.BROWSER_COMPATIBLE); | |
for (Iterator it = _params.keySet().iterator(); it.hasNext();) { | |
String key = (String) it.next(); | |
if (_params.get(key) instanceof File) { | |
FileBody fileBody = new FileBody((File) _params.get(key)); | |
entity.addPart(key, fileBody); | |
} else { | |
entity.addPart(key, | |
new StringBody((String) _params.get(key))); | |
} | |
} | |
request.setEntity(entity); | |
} catch (Exception e) { | |
new ServerConnectionException(e); | |
} | |
return request; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment