试了很多次就是查不到信息,求高手看看!!!网址:http://gaj.baoji.gov.cn/gongancar/index.asp
用例:陕C11540我的代码: public static String getPost(String str_url){
try {
URL url = new URL(str_url);
HttpURLConnection urlConn = (HttpURLConnection)url.openConnection();
urlConn.setRequestMethod("POST");
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setInstanceFollowRedirects(true);
urlConn.connect();
DataOutputStream out = new DataOutputStream(urlConn.getOutputStream());
String content = "cbh=陕C11540";
out.writeBytes(content);
out.flush();
out.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String inputLine = null;
while((inputLine = reader.readLine()) != null){
System.out.println(inputLine);
}
reader.close();
urlConn.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
用例:陕C11540我的代码: public static String getPost(String str_url){
try {
URL url = new URL(str_url);
HttpURLConnection urlConn = (HttpURLConnection)url.openConnection();
urlConn.setRequestMethod("POST");
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setInstanceFollowRedirects(true);
urlConn.connect();
DataOutputStream out = new DataOutputStream(urlConn.getOutputStream());
String content = "cbh=陕C11540";
out.writeBytes(content);
out.flush();
out.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String inputLine = null;
while((inputLine = reader.readLine()) != null){
System.out.println(inputLine);
}
reader.close();
urlConn.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
解决方案 »
- 求软件:Java Service Wrapper for windows(x64)
- 要上ESB+工作流,给推荐个开源吧!
- struts分模块开发具体怎样建立各模块的
- 为什么tomcat每次重启都要重新部署
- jbuilder2005如何访问远程Weblogic及远程Oracle数据库?
- 能否推荐一个ejb+jb+weblogic 的教程.谢谢
- webwork连接spring
- 急!实体bean(cmp)访问SQLServer2000的问题!大家来看看
- 几个考试问题
- j2ee 在window2k 下的安装和配置 问题?
- Xfire发布到Tomcat,启动报错
- 不显示删除回复显示所有回复显示星级回复显示得分回复 为什么我的JAVA程序在DOS命令下可以编译执行却报错
哎...自己拿ie打开了看看...查询那个按钮的地址是
http://gaj.baoji.gov.cn/gongancar/find.asp
哦 帖子上面是我写错了
是这个http://gaj.baoji.gov.cn/gongancar/find.asp
你试试这个能获取到么?
try {
URL dataUrl = new URL("http://gaj.baoji.gov.cn/gongancar/find.asp");
HttpURLConnection con = (HttpURLConnection) dataUrl
.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setDoInput(true); OutputStream os = con.getOutputStream();
os.write("cbh=陕C11540".getBytes());
os.flush();
os.close(); InputStream is = con.getInputStream();
byte d[] = new byte[1024];
int size = 0;
while ((size = is.read(d)) != -1)
System.out.println(new String(d, 0, size)); con.disconnect();
} catch (Exception ex) {
ex.printStackTrace();
}
结果<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style2 { font-size: 16px;
font-weight: bold;
}
.style4 {font-size: 16px; font-weight: bold; color: #FF0000; }
.style5 {color: #FFFFFF}
.style6 {color: #FF0000}
-->
</style></head><body><div align="center"><br />
<span class="style2"><br />
<br />
<br />
<span class="style6">尚无您的违章信息!</span></span><span class="style6"><br />
</span>
</div>
</body>
</html>
有可能接收到的是乱码,
还有一种情况我无法理解就是http://gaj.baoji.gov.cn/gongancar/find.asp?cbh=陕C,也是查不到数据的,超越了我的理解范围
加上这句
我用IE截下了原本生成的cookie,加上就有数据了
con.setRequestProperty("Cookie", "ASPSESSIONIDSADDADDB=ALKIHJNBKLFFGEOFPJPKAMEH");应该是服务器上做session认证了
不太清楚asp的sessionid生成机制,你想办法能生成对应的sessionid应该就能访问了