- WebService是发布在网络上的API,可以通过发送XML调用,WebService返回结果也是XML数据
- WebService没有语言限制,只要可以发送XML数据和接收XML数据即可
- http://www.webxml.com.cn 网站上提供了一些WebService服务,我们可以对其进行调用
- http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?op=getMobileCodeInfo 中提供了电话归属地查询的使用说明
六、访问WebService
public void query(View v) {
String number = numberET.getText().toString().trim();
String url = "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo";
RequestParams params = new RequestParams();
params.put("mobileCode", number);
params.put("userID", "");
client.get(url, params, new TextHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, String responseString) {
try {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(new StringReader(responseString));
for (int type = parser.getEventType(); type != XmlPullParser.END_DOCUMENT; type = parser.next())
if (type == XmlPullParser.START_TAG && "string".equals(parser.getName()))
addressTV.setText(parser.nextText());
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
Toast.makeText(getApplicationContext(), "出错了 " + statusCode, Toast.LENGTH_SHORT).show();
throwable.printStackTrace();
}
});
}
示例源码->百度网盘