restful webserice
package com.onetown.action.admin; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; /** * Created by IntelliJ IDEA. * User: Administrator * Date: 11-7-12 * Time: 下午4:59 * To change this template use File | Settings | File Templates. */ public class TestFUL { public static void main(String[] args){ URL url= null; try { url = new URL("http://localhost:8080/struts2-rest-showcase/orders"); } catch (MalformedURLException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } HttpURLConnection con = null; try { con = (HttpURLConnection)url.openConnection(); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } try { con.setRequestMethod("GET"); } catch (ProtocolException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } try { con.connect(); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } InputStream in= null; try { in = con.getInputStream(); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } byte[] b= new byte[1024]; int result= 0; try { result = in.read(b); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } while( result!=-1){ System.out.write(b,0,result); try { result= in.read(b); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } } }
相关推荐
Eiceblue 2020-08-02
ahnjwj 2020-07-28
playis 2020-06-28
playis 2020-06-16
ahnjwj 2020-06-12
84560296 2020-06-10
84560296 2020-06-09
84560296 2020-06-08
84560296 2020-05-30
81901836 2020-05-26
beibeijia 2020-05-16
85291545 2020-05-01
84560296 2020-04-10
fanix 2020-04-09
bapinggaitianli 2020-04-07
84560296 2020-03-27
85291545 2020-03-26
82911731 2020-03-25