Java里面有没有能实现和.net里webrequest相同功能的类呀?
就是可以自动提交form请求并能获取返回页面结果的?
各位大虾给帮帮忙?

解决方案 »

  1.   

    httpclient:
    http://www.apache.org
      

  2.   

    楼上的兄弟请问httpclient支持asp等其它页面吗?我听说它只支持php的,不知道有没有这方面的限制,以前没有用过这个东东,别笑俺
      

  3.   

    URL urlstr = new URL(urlString);
    logger.info(urlString + "?" + strb.toString());
    URLConnection urlConnection = urlstr.openConnection();
    urlConnection.setRequestProperty("content-type",
    "application/x-www-form-urlencoded;charset=utf-8");
    urlConnection.setDoOutput(true);
    PrintWriter out = new PrintWriter(urlConnection.getOutputStream());
    String postContent = new String(strb.toString()); out.println(postContent);
    out.close(); urlConnection.connect(); BufferedReader in = new BufferedReader(new InputStreamReader(
    urlConnection.getInputStream()));in.close();
      

  4.   

    to 叶子:
    能麻烦你一下吗?解释一下你的程序,有些地方没明白.我要做的是一个自动程序,就是模拟人将一些数据自动填充到form中,并自动提交,对远端的数据库进行查询
      

  5.   

    模拟人填充form其实就是URLConnection 模拟http协议写过去,叶子的是写核心部分,至于你要怎么自动化那是根据你的具体要求,别人不能替你想。
    对数据库查询,用jdbc做,高级点用CacheRowSet做
      

  6.   

    URL urlstr = new URL(urlString);
    logger.info(urlString + "?" + strb.toString());
    URLConnection urlConnection = urlstr.openConnection();
    urlConnection.setRequestProperty("content-type",
    "application/x-www-form-urlencoded;charset=utf-8");//设置http的mime
    urlConnection.setDoOutput(true);
    PrintWriter out = new PrintWriter(urlConnection.getOutputStream());
    String postContent = new String(strb.toString());out.println(postContent);//写出http协议的数据,和网页上的click后做的事一样的
    out.close();urlConnection.connect();BufferedReader in = new BufferedReader(new InputStreamReader(
    urlConnection.getInputStream()));in.close();