Skip to content

Instantly share code, notes, and snippets.

@adolfobrunno
Created July 2, 2015 02:37
Show Gist options
  • Save adolfobrunno/4f14232b81487446b664 to your computer and use it in GitHub Desktop.
Save adolfobrunno/4f14232b81487446b664 to your computer and use it in GitHub Desktop.
public class TestPost {
final static String URL = "http://45.55.92.161:8080/medcloud-api/image/new";
final static String URL_DEV = "http://localhost:8080/api/image/new";
final static String fileName = "C:\\Users\\Adolfo\\Downloads\\teste.jpg";
final static String USER_TOKEN = "f4660e71-e5a6-46a0-9189-ea849cdd7755";
public static void main(String[] args) throws IllegalStateException, IOException {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(URL);
String boundary = "-------------" + System.currentTimeMillis();
String jsonBody = "{ \"type\": \"CT\", "+
"\"iid\" : \"1.5496.1231584.5412\","+
"\"creation_date\" : \"20150623\","+
"\"size\" : \"450000\","+
"\"cid\" : \"1.46548.21354\","+
"\"user_token\": \""+USER_TOKEN+"\"}";
StringBody json = new StringBody(jsonBody, ContentType.APPLICATION_JSON);
FileBody file = new FileBody(new File(fileName));
HttpEntity entity = MultipartEntityBuilder.create()
.setBoundary(boundary)
.addPart("file", file)
.addPart("properties", json)
.build();
httpPost.setEntity(entity);
HttpResponse response = httpclient.execute(httpPost);
System.out.println(response.getStatusLine());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment