webservice _ 号码归属地查询
发布时间:2020-12-17 00:03:04 所属栏目:安全 来源:网络整理
导读:参考网址: webservice.webxml.com.cn ? ? ? ? --------------------------------------------------------------------------- 号码归属地查询: public ? class ? MainActivity ? extends ? Activity ? implements ? OnClickListener { ?????? private ? Edi
参考网址: webservice.webxml.com.cn ? ? ? ?
---------------------------------------------------------------------------
号码归属地查询:
public
?
class
?
MainActivity
?
extends
?
Activity
?
implements
?
OnClickListener {
??????
private
?
EditText??
?
et
;
??????
private
?
Button???
?
bt
;
??????
private
?
TextView?
?
tv
;
??????
??????
??????
@Override
??????
protected
?
void
?
onCreate(Bundle savedInstanceState) {
????????????
?
super
.onCreate(savedInstanceState);
????????????setContentView(R.layout.
?
activity_main
);
????????????
????????????
?
et
=(EditText) findViewById(R.id.
?
et
);
????????????
?
bt
=(Button) findViewById(R.id.
?
bt
);
???????
?
tv
=(TextView) findViewById(R.id.
?
iv
);??????????
????????????
????????????
?
//注册按钮监听器
???????
?
bt
.setOnClickListener(
?
this
);
??? }
??????
?
/**
??????? * 按钮触发事件
??????? */
??????
@Override
??????
public
?
void
?
onClick(View v) {
????????????
????????????String number=
?
et
.getText().toString().trim();??
?
//获取号码
????????????String path=
"http://webservice.webxml.com.cn//WebServices/MobileCodeWS.asmx/getMobileCodeInfo"
?
;
????????????
????????????
????????
?
//创建AsyncHttpClient对象
?????? AsyncHttpClient? client=
?
new
?
AsyncHttpClient();
?????? RequestParams params=
?
new
?
RequestParams();
?????? params.put(
?
"mobileCode"
,number);
?????? params.put(
?
"userID"
,
?
""
);
??????
???????
?
//获取网络xml文件
????????????client.get(path,params,
?
new
?
AsyncHttpResponseHandler(){
??????? ????
??????? ????
?
@Override
??????? ????
?
public
?
void
?
onSuccess(String content) {
??????? ??????
?
try
?
{
??????????????????????????????
?
//创建pull解析器
??????????????????????????????XmlPullParser parser = Xml.newPullParser();?
??????????????????????????????parser.setInput(
?
new
?
StringReader(content));??
?
//解析?xml字节流
??????????????????????????????
?
for
(
?
int
?
type=parser.getEventType();type!=XmlPullParser.
END_DOCUMENT
?
;type=parser.next()){
????????????????????????????????????
?
if
(type == XmlPullParser.
?
START_TAG
?
&&
?
"string"
.equals(parser.getName())){
??????????????????????????????????????????
?
tv
.setText(parser.nextText());
????????????????????????????????????}
????????????????????????????????????
??????????????????????????????}
??????????????????????????????
????????????????????????}
?
catch
?
(Exception e) {
????????????????????????
??????????????????????????????e.printStackTrace();
??????????????????????????????System.
?
out
.println(
?
"请求失败..."
);
????????????????????????}
???????????? }
??????? ????
??????? });
????????????
??????? }
????????????
??????}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |