首先感谢一下各位大神能前来帮助,谢谢.
下面直入主题:
我现在需要写一个JAVA程序,模拟发送web请求,然后接收web响应,返回的内容,再对数据内容进行分析,取出需要的数据。
我有几个问题想请教一下:
1,怎么模拟发送web请求,比如模拟带参数提交一个表单。
2. 如何接收返回的内容。
只要能接收返回的内容,分析应该不是大问题了,
请各位指点一下,之前从未涉及过这个。谢谢了!

解决方案 »

  1.   

    给你个例了。用的是HttpClient ,请求和接收数据public static void main(String[] args) {
     String ip="14.147.43.45";
     String url = "http://www.ip138.com/ips.asp";
     HttpClient client = new HttpClient();
     PostMethod method = new PostMethod(url);
     method.setParameter("ip", ip);
      method.getParams().setContentCharset("GBK");
     // method.setRequestHeader("Content-Length", 858585+"");
     try {
    client.executeMethod(method);
    int statecode = method.getStatusCode();
                if (statecode == HttpStatus.SC_OK) {
                  String temp=method.getResponseBodyAsString();
              String rex = "<li>.*</li>";
              Pattern p = Pattern.compile(rex);
              Matcher m = p.matcher(temp);
                    if(m.find()){
                     System.out.println(m.group());
                    }            }
    } catch (HttpException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
        }
      

  2.   

    http://topic.csdn.net/u/20110809/10/aadbb291-f1f1-4619-9152-8c47a34c5815.html
    看这个帖子,我的回复。
      

  3.   

    数据内容进行分析 : jsoup