快速入门
当我们输入一个号码,它就能够查询出我们的手机位置信息:
我们现在要做的就是将这个服务让我们自己写的应用程序中也可以调用,那怎么做呢???
http-get方式访问webservice
public void get(String mobileCode ,String userID ) throws Exception{
URL url=new URL("http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo?mobileCode="+mobileCode+
"&userID="+userID);
HttpURLConnection conn=(HttpURLConnection) url.openConnection();
conn.setConnectTimeout();
conn.setRequestMethod("GET");
if(conn.getResponseCode()==HttpURLConnection.HTTP_OK){ //结果码=200
InputStream is=conn.getInputStream();
//内存流 ,
ByteArrayOutputStream boas=new ByteArrayOutputStream();
byte[] buffer=new byte[];
int len=-;
while((len=is.read(buffer))!=-){
boas.write(buffer, , len);
}
System.out.println("GET请求获取的数据:"+boas.toString());
boas.close();
is.close();
}
}