可以到http://www.chinamobile.com/ZZFW/hdcx.asp?ClassID=2&ClassChild_ID=19
这个是移动网站查手机号归属地的页面。我要访问http://www.chinamobile.com/ZZFW/Search_Result.asp?ClassID=2&ClassChild_ID=19这个asp页面是post提交的,现在要加一个参数phoneNo=?请问如何通过java实现这个程序?

解决方案 »

  1.   

    去看看java.net包的URLConnection,可以post传参!
      

  2.   

    估计LZ想做个JAVA界面 查询手机相关信息的 而数据源来自于这个WEB吧
    JAVA.NET包下的URL 看下 这个和JAVA其实关系不是很大,看成访问WEB
      

  3.   

    数据是在http://www.chinamobile.com/ZZFW/Search_Result.asp?ClassID=2&ClassChild_ID=19
    这里的,通过手机号可以查询所属地区,比如北京的就是010。我试了在链接上加上参数,但是无效,源码显示网页是通过post方式传过去的手机号。有什么方法可以解决。最好有具体的代码。谢谢
      

  4.   

    首先回答一下上面朋友的问题我是要在移动WEB网站上查手机号归属地,不会和移动发生费用问题。之所以要上移动那里查,是因为有些手机新号码的归属地只有移动的数据库里有。import java.net.HttpURLConnection;
    import java.net.URL;
    import java.net.URLConnection;
    import java.io.*;
    import org.apache.log4j.Logger;
    import org.apache.log4j.PropertyConfigurator;public class HttpRequest {

    HttpURLConnection conn = null;
    private static Logger elogger = Logger.getLogger("Prosten_ERROR"); public String getArea(String phone) {

    String area = null;
    String str = "http://www.chinamobile.com/ZZFW/Search_Result.asp?ClassID=2&ClassChild_ID=19&phoneNo="+phone;
    try {
    URL url = new URL("http://www.chinamobile.com/ZZFW/Search_Result.asp?ClassID=2&ClassChild_ID=19&phoneNo="+phone);
    conn = (HttpURLConnection)url.openConnection();
    conn.setDoOutput( true );
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type","text/xml");
        conn.setRequestProperty( " Content-Length " , String.valueOf(str.length()));
        conn.setDoOutput( true );
        conn.setDoInput( true );
        conn.connect();
        int code = conn.getResponseCode();
        System.out.println("code   " + code);      BufferedReader in = new BufferedReader( new InputStreamReader(conn.getInputStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null )   {
          area += inputLine + "\n" ;  
        } 
        in.close();
    }catch (Exception ex)  {
    elogger.error("Error:" + ex.getMessage());
        return null;

    return area;
    }

    public static void main(String[] args) {
    PropertyConfigurator.configure("/log4j.properties");
    HttpRequest t = new HttpRequest();
    String str = null;
    str = t.getArea("13682656987");
    System.out.println("as:"+str);
    }

    上面的程序请各位看一下有什么问题,返回的getResponseCode一直是411下面str一直是null