List of usage examples for org.apache.http.entity.mime.content StringBody StringBody
public StringBody(final String text) throws UnsupportedEncodingException
From source file:org.dineth.shooter.client.Example.java
public static void main(String[] args) { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://localhost:8080/upload"); filename = "router.jpg"; FileBody bin = new FileBody(new File(filename)); StringBody fileName = null;//from w w w. j a v a2 s . c o m try { fileName = new StringBody(filename); } catch (UnsupportedEncodingException ex) { Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, ex); } MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart("file", bin); reqEntity.addPart("filename", fileName); httppost.setEntity(reqEntity); HttpResponse response = null; try { response = httpclient.execute(httppost); } catch (IOException ex) { Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, ex); } HttpEntity resEntity = response.getEntity(); }
From source file:httpclient.entity.mime.ClientMultipartFormPost.java
public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.println("File path not given"); System.exit(1);/*from w w w .ja v a2 s . co m*/ } HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://localhost:8080" + "/servlets-examples/servlet/RequestInfoExample"); FileBody bin = new FileBody(new File(args[0])); StringBody comment = new StringBody("A binary file of some kind"); MultipartEntity reqEntity = new MultipartEntity(); // reqEntity.addPart("bin", bin); // reqEntity.addPart("comment", comment); // httppost.setEntity(reqEntity); System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (resEntity != null) { System.out.println("Response content length: " + resEntity.getContentLength()); System.out.println("Chunked?: " + resEntity.isChunked()); } if (resEntity != null) { resEntity.consumeContent(); } }
From source file:com.dlmu.heipacker.crawler.examples.entity.mime.ClientMultipartFormPost.java
public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.println("File path not given"); System.exit(1);/*from w ww . j a v a2 s .co m*/ } HttpClient httpclient = new DefaultHttpClient(); try { HttpPost httppost = new HttpPost( "http://localhost:8080" + "/servlets-examples/servlet/RequestInfoExample"); FileBody bin = new FileBody(new File(args[0])); StringBody comment = new StringBody("A binary file of some kind"); MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart("bin", bin); reqEntity.addPart("comment", comment); httppost.setEntity(reqEntity); System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (resEntity != null) { System.out.println("Response content length: " + resEntity.getContentLength()); } EntityUtils.consume(resEntity); } finally { try { httpclient.getConnectionManager().shutdown(); } catch (Exception ignore) { } } }
From source file:com.tianya.ClientMultipartFormPost.java
public static void main(String[] args) throws Exception { /*/*from w ww . j av a2 s . c om*/ if (args.length != 1) { System.out.println("File path not given"); System.exit(1); } */ HttpClient httpclient = new DefaultHttpClient(); String posturl = "http://letushow.com/submit"; preGet(httpclient); try { HttpPost httppost = new HttpPost(posturl); FileBody bin = new FileBody(new File("/Users/gypsai/Desktop/letushow/let.gif")); StringBody title = new StringBody("let"); MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart("imgfile", bin); reqEntity.addPart("csrf_token", new StringBody(csrf_token)); reqEntity.addPart("title", title); reqEntity.addPart("type", new StringBody("local")); httppost.setEntity(reqEntity); System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (resEntity != null) { // System.out.println("Response content length: " + resEntity.getContentLength()); System.out.println(iotostring(response.getEntity().getContent())); } EntityUtils.consume(resEntity); } finally { try { httpclient.getConnectionManager().shutdown(); } catch (Exception ignore) { } } }
From source file:com.waku.mmdataextract.ComprehensiveSearch.java
@SuppressWarnings("deprecation") private static MultipartEntity getMultipartEntity(String brandId, int pageNumber) { MultipartEntity reqEntity = new MultipartEntity(); try {/*from w w w . jav a2 s .c o m*/ reqEntity.addPart("flag", new StringBody("search")); reqEntity.addPart("brandId", new StringBody(brandId)); reqEntity.addPart("currentPage", new StringBody(pageNumber + "")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return reqEntity; }
From source file:net.asplode.tumblr.TextPost.java
public TextPost() { try {//from w w w .j a v a 2 s . c o m entity.addPart("type", new StringBody("regular")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
From source file:net.asplode.tumblr.QuotePost.java
public QuotePost() { try {/*from w w w . j av a2s . c o m*/ entity.addPart("type", new StringBody("quote")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
From source file:net.asplode.tumblr.LinkPost.java
public LinkPost() { try {//from w w w .j av a2s . co m entity.addPart("type", new StringBody("link")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
From source file:net.asplode.tumblr.ConversationPost.java
public ConversationPost() { try {/* w w w . jav a 2s.com*/ entity.addPart("type", new StringBody("conversation")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
From source file:net.asplode.tumblr.AudioPost.java
public AudioPost() { try {//w w w . ja v a 2 s . c om entity.addPart("type", new StringBody("audio")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }