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

如何通过JAVA程序向一个ASP站点提交参数,并读取返回的查询结果?
URL   url   =   new   URL( "http://qq.ip138.com/train/train_search.asp?trainname=2046 ");
        //URL   url   =   new   URL( "http://localhost:8080/url/result.jsp ");
                String   name= "trainname=2046 ";
                HttpURLConnection   connection   =   (HttpURLConnection)   url.openConnection();
                connection.setRequestMethod( "POST ");
                connection.setDoOutput(true);
                connection.setDoInput(true);
                PrintWriter   out   =   new   PrintWriter(connection.getOutputStream());
                out.println(name);
                out.flush();
                out.close();
               
                int   code=connection.getResponseCode();
                if(code!=connection.HTTP_OK)
                {
                System.out.println( "error   code: "+code);
                }  
                BufferedReader   in
                        =   new   BufferedReader(new   InputStreamReader(connection.getInputStream()));
                String   line;
                while   ((line   =   in.readLine())   !=   null)   {
                        System.out.println(line);
                }
                in.close();
就是通过JAVA程序向一个列车车次查询站点提交列车车次,并读取返回的查询结果,各位大侠帮忙看看啊,上面的程序返回结果里面没有需要的车次信息,各位帮忙看看是哪里的问题啊,十万火急啊,

------解决方案--------------------
嗯,我也想学习下,同问.要是php程序呢??谢谢
------解决方案--------------------
connection.setRequestMethod( "POST ");
你在url里面已经传输了参数了
就没必要再setpost了吧?
因为url传参数就是用get的的方法的啊

你直接在ie里面访问看看有些什么结果

然后再把在java里面的结果贴出来
做个对比,看看是报什么错


------解决方案--------------------
程序看不出问题

应该是那的那个站点问题被,可能是屏蔽了什么东西了吧可能是