WebService通过Get方式调用第三方查询电话号码归属地

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dj7858177/article/details/80345979
/**
 * 调用第三方服务查询电话号码归属地服务
 * @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("13889830573", "");
}
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页