10. 查看天气预报
HttpGet get = new HttpGet(
"http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/
getWeatherbyCityName?theCityName=珠海");
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(get);
InputStream ins = response.getEntity().getContent();
byte[] b = new byte[1024];
StringBuilder sb = new StringBuilder();
while (ins.read(b) != -1) {
sb.append(new String(b, "UTF-8"));
}
System.out.println(sb.toString());
11. 查看股票信息HttpGet get = new HttpGet(
"http://www.webxml.com.cn/WebServices/
ChinaStockWebService.asmx/getStockImageByCode?theStockCode="
);
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(get);
InputStream is = response.getEntity().getContent();
FileOutputStream fos = new FileOutputStream("d:/stock.gif");
BufferedInputStream bis = new BufferedInputStream(is);
BufferedOutputStream bos = new BufferedOutputStream(fos);
int b = 0;
while ( (b=bis.read()) !=-1) {
bos.write(b);
}
bis.close();
bos.close();
12. REST/ HelloWorld@Path("/hello/")
public class HelloWS {
@GET
@Path("/hi")
public String sayHi(@QueryParam("name") String name) {
return "hello " + name;
}
}
public class HelloServer {
public static void main(String[] args) {
JAXRSServerFactoryBean server =
new JAXRSServerFactoryBean();
server.setResourceClasses(HelloWS.class);
server.setAddress("http://localhost:9009");
server.create();
}
}