/**
* 调用第三方服务查询电话号码归属地服务
* @author dw
* @Time 2018/5/16
*
*/
public class MobileCodeService {
//1.get方式访问WebService
public void get(String mobileCode,String userID) throws IOException{
URL url = new URL("http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo?mobileCode="+mobileCode+"&userID="+userID);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//设置延时时间
conn.setConnectTimeout(5000);
//设置请求方式
conn.setRequestMethod("GET");
if (conn.getResponseCode()==HttpURLConnection.HTTP_OK) { //连接成功200
InputStream is = conn.getInputStream();
//内存流
ByteArrayOutputStream boas = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = -1;
//边读边写,从外部读进来,再写进内存
while((len = is.read(buffer))!=-1){
boas.write(buffer, 0, len);
}
System.out.println("Get请求获取的数据:"+boas.toString());
boas.close();
is.close();
}
}
public static void main(String[] args) throws IOException {
MobileCodeService ws = new MobileCodeService();
ws.get("1388983****", "");
}
WebService通过Get方式调用第三方查询电话号码归属地
最新推荐文章于 2021-04-09 09:54:55 发布