android 手机号码归属地查询

编程入门 行业动态 更新时间:2024-10-13 10:23:08

android  <a href=https://www.elefans.com/category/jswz/34/1702735.html style=手机号码归属地查询"/>

android 手机号码归属地查询

2019独角兽企业重金招聘Python工程师标准>>>

package com.cy.contact;import java.io.IOException;
import java.io.InputStream;
import java.HttpURLConnection;
import java.URL;import org.xmlpull.v1.XmlPullParser;import android.content.Context;
import android.util.Xml;/** * @author 作者wangqiang* @version 创建时间:2012-12-29 下午04:36:51 * */
public class DialHttp {public String query(String num,Context context) throws Exception { InputStream in = this.getClass().getClassLoader().getResourceAsStream("number_address.xml"); byte[] data = load(in); String xml = new String(data); xml = xml.replace("#", num); byte[] sendData = xml.getBytes("UTF-8"); // 发送到代理的地址上 URL url = new URL( ".asmx"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type","application/soap+xml; charset=utf-8"); conn.setRequestProperty("Content-Length", String.valueOf(sendData.length)); // 将请求的xml发送出去 conn.setDoOutput(true); conn.getOutputStream().write(sendData); // 获取从服务器传回来的数据 if (conn.getResponseCode() == 200) {return parse(conn.getInputStream());}return null; } // 解析流拿到getMobileCodeInfoResult中的数据 private String parse(InputStream inputStream) throws Exception { XmlPullParser parser = Xml.newPullParser(); parser.setInput(inputStream, "UTF-8"); // 查找getMobileCodeInfoResult标签,获取标签中的数据 for (int event = parser.getEventType(); event != XmlPullParser.END_DOCUMENT; event = parser .next()) switch (event) { case XmlPullParser.START_TAG: if ("getMobileCodeInfoResult".equals(parser.getName())) return parser.nextText(); } return null; } public byte[] load(InputStream in) throws IOException{byte b[] = new byte[1024];int len = 0;int temp = 0;while((temp = in.read()) != -1){b[len] = (byte)temp;len++;}in.close();return b;}    }
src下放xml文件
<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi=""xmlns:xsd="" xmlns:soap12=""> <soap12:Body> <getMobileCodeInfo xmlns="/"> <mobileCode>#</mobileCode> <userID></userID> </getMobileCodeInfo> </soap12:Body> 
</soap12:Envelope>

得到数据格式  省+城市
	VerNumeral ver = new VerNumeral();String number = "13576127225:江西 南昌 江西移动全球通卡";String str[] = number.split(":");String[] m = str[1].split(" ");String result = m[0]+m[1];System.out.println("m[2]--"+m[2]);System.out.println("s--"+result);

转载于:

更多推荐

android 手机号码归属地查询

本文发布于:2024-02-26 13:51:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1702734.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:手机号码归属地查询   android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!