Created
April 10, 2013 06:57
-
-
Save mess110/5352394 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public void post(String url, List<NameValuePair> nameValuePairs) { | |
| HttpClient httpClient = new DefaultHttpClient(); | |
| HttpContext localContext = new BasicHttpContext(); | |
| HttpPost httpPost = new HttpPost(url); | |
| try { | |
| MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); | |
| for(int index=0; index < nameValuePairs.size(); index++) { | |
| if(nameValuePairs.get(index).getName().equalsIgnoreCase("image")) { | |
| // If the key equals to "image", we use FileBody to transfer the data | |
| entity.addPart(nameValuePairs.get(index).getName(), new FileBody(new File (nameValuePairs.get(index).getValue()))); | |
| } else { | |
| // Normal string data | |
| entity.addPart(nameValuePairs.get(index).getName(), new StringBody(nameValuePairs.get(index).getValue())); | |
| } | |
| } | |
| httpPost.setEntity(entity); | |
| HttpResponse response = httpClient.execute(httpPost, localContext); | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment