如何从网站电话号码中找到运营商名称在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
    

要回复问题请先登录注册