试了很多次就是查不到信息,求高手看看!!!网址: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 "";
}

解决方案 »

  1.   

    http://gaj.baoji.gov.cn/gongancar/index.asp
    哎...自己拿ie打开了看看...查询那个按钮的地址是
    http://gaj.baoji.gov.cn/gongancar/find.asp
      

  2.   


    哦 帖子上面是我写错了 
    是这个http://gaj.baoji.gov.cn/gongancar/find.asp
    你试试这个能获取到么?
      

  3.   


    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>
      

  4.   

    经过我的测试,你的代码模拟post是很成功的,我自己的网站是可以接收到参数的,但是会产生中文乱码,乱码这个东东是需要服务器协调的,所以http://gaj.baoji.gov.cn/gongancar/index.asp
    有可能接收到的是乱码,
    还有一种情况我无法理解就是http://gaj.baoji.gov.cn/gongancar/find.asp?cbh=陕C,也是查不到数据的,超越了我的理解范围
      

  5.   

    测出来了,这个傻X 2呆网站,必须把cookie写在head头上
    加上这句 
    我用IE截下了原本生成的cookie,加上就有数据了
    con.setRequestProperty("Cookie", "ASPSESSIONIDSADDADDB=ALKIHJNBKLFFGEOFPJPKAMEH");应该是服务器上做session认证了
    不太清楚asp的sessionid生成机制,你想办法能生成对应的sessionid应该就能访问了
      

  6.   

    IE截下了原本生成的cookie,加上就有数据