日期:2014-05-18  浏览次数:20751 次

模拟post发送信息查询,并获取查询结果页的html代码!(分值可增加)
把要查询的ip地址     发送给http://www.ip138.com/     查询,并获得查询后的网页html代码

------解决方案--------------------
用HttpClient来模拟浏览器GET POST

http://myrss.easyjf.com/html/20070710/27296660-1356479.htm
------解决方案--------------------
用程序查询ip的话可以用下面这个,比http://www.ip138.com/好用:
http://www.ip.com.cn/ip.php?q=211.12.12.21


public static void main(String[] args) {
try{
URL url = new URL( "http://www.ip.com.cn/ip.php?q=211.12.12.21 ");
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while(true){
int b = is.read();
if (b == -1){
break;
}
bos.write(b);
}
String result = bos.toString();
System.out.println(result);
is.close();
bos.close();
}catch(IOException ioe){
ioe.printStackTrace();
}
}

------解决方案--------------------
NameValuePair simcard = new NameValuePair( "ip ", "211.144.151.110 ");
post.setRequestBody(new NameValuePair[] { simcard });
此处增加另一个参数,你少了一个参数.

问题解决!