如何解决如何从网站电话号码中找到运营商名称在Android应用程序中搜索页面?
| 我需要从电话号码中找到操作员姓名。在我的android应用程序中使用此网站。 在应用程序中请求和解析HTML可以正常工作。 当我从应用程序查询请求字符串时: 地址:.https://nummertjanster.pts.se/net/zh/Nummerkapacitet/Enskiltnummer?&_rp / pts.SearchNumber_ndc = 70&_rp / pts.SearchNumber_operator = Tele2 + sverige + AB&_rp / pts.SearchNumber_telnumber = 4264128 我需要指定\'operator name \'..我猜这很奇怪。 问题是,如果我在请求字符串中指定了运算符名称,无论输入哪个数字(ndc-telnumber),结果网页都会显示该运算符名称。 以下是一些要测试的数字: 073-3355433 = Telenor sverige AB 073-6107353 = Tele 2 sverige AB 070-3999266 = TeliaSonera sverige AB 073-2404070 = Glocalnet AB 如何找到特定号码的正确操作员名称? 感谢您的帮助。解决方法
该网站存在一些问题,无法正常工作:
它需要一个cookie才能使POST起作用。
实际上,操作员名称不是作为页面的一部分返回的,而是作为位置重定向的一部分返回的(302)。
这段代码完成了您想要的操作(我在躲避工作,所以我实际上为您整理了一下):它访问主页,获取/提取返回的Cookie,将区号和区号发布到网站上,然后拦截位置标头并提取操作员名称。请注意,区号并不总是3位数字(例如,对于073-3355433,您应该输入
String operatorName = findOperator(\"73\",\"3355433\");
。
String findOperator(String ndc,String number)
{
String parameters = \"action=search&ndc=\"+ndc+\"&number=\"+number+\"&search=S%F6k\";
HttpURLConnection httpUrlConnection = null;
OutputStream outputStream = null;
InputStream inputStream = null;
int code = 0;
String response = null;
try {
java.net.URI u = new java.net.URI(\"https://nummertjanster.pts.se/net/sv/Nummerkapacitet/Enskiltnummer\");
httpUrlConnection = (HttpURLConnection) u.toURL().openConnection();
httpUrlConnection.setConnectTimeout(7500);
httpUrlConnection.setReadTimeout(7500);
httpUrlConnection.setRequestMethod(\"GET\");
httpUrlConnection.connect();
String cookie = httpUrlConnection.getHeaderField(\"Set-Cookie\");
u = new java.net.URI(\"https://nummertjanster.pts.se/actionrequest/sv/Nummerkapacitet/Enskiltnummer?__ac_/pts.SearchNumber\");
httpUrlConnection = (HttpURLConnection) u.toURL().openConnection();
httpUrlConnection.setConnectTimeout(7500);
httpUrlConnection.setReadTimeout(7500);
httpUrlConnection.setRequestProperty(\"Cookie\",cookie);
httpUrlConnection.setRequestMethod(\"POST\");
httpUrlConnection.setDoOutput(true);
httpUrlConnection.connect();
outputStream = httpUrlConnection.getOutputStream();
outputStream.write(parameters.getBytes(\"UTF-8\"));
httpUrlConnection.setInstanceFollowRedirects(false);
try {
inputStream = httpUrlConnection.getInputStream();
} catch (IOException e) {
//andrologger.warn(\"An error occurred while POSTing to \" + url,e);
}
code = httpUrlConnection.getResponseCode();
response = httpUrlConnection.getHeaderField(\"Location\");
if(response != null){
response = response.split(\"&\")[2].split(\"=\")[1];
}
}catch(Exception e1){
android.util.Log.v(\"Configuration\",\"Exception: \"+e1.getMessage(),e1);
} finally {
closeQuietly(outputStream);
closeQuietly(httpUrlConnection);
}
return response;
}
在我的手机上对其进行了测试,效果很好:让我知道它如何为您工作。
, 显然它无法正常工作。您将不得不寻找另一种方式。
也许模仿页面正在执行的表单发布:http://www.androidsnippets.com/executing-a-http-post-request-with-httpclient
编辑这是行不通的
很简单:
https://nummertjanster.pts.se/net/sv/Nummerkapacitet/Enskiltnummer?&__rp_/pts.SearchNumber_ndc=PUT_AREA_NUMBER_HERE&__rp_/pts.SearchNumber_operator=xxno_operatorxx&__rp_/pts.SearchNumber_telnumber=PUT_NUMBER_HERE
即
https://nummertjanster.pts.se/net/sv/Nummerkapacitet/Enskiltnummer?&__rp_/pts.SearchNumber_ndc=696&__rp_/pts.SearchNumber_operator=xxno_operatorxx&__rp_/pts.SearchNumber_telnumber=1788300
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。