我要用java打开google的搜索引擎进行搜索,实现方法是
exeplorer.exe http://www.google.com/search?hl=ja&q=aaaaaa&lr=
但是如果后面的参数过长的时候,比如说q=后面跟1000个字符,这时候用这个方法的话,url过长的部分将会被自动截掉,请问各位兄弟姐妹,除了上面的方法还有什么方法能让我打开搜索引擎并且超长的字符不会被截掉?非常着急,请各位多多帮忙
注:     开发的不是基于web的程序!!!!

解决方案 »

  1.   

    post提交的结果怎么用浏览器打开阿
      

  2.   

    结果可以getInputStream以流的形式获得。
    你现在到底是在浏览器中打开页面还是在程序中发请求?
      

  3.   

    <!-- Search Google -->
    <center>
    <form method=get action="http://www.google.com/search">
    <table bgcolor="#FFFFFF"><tr><td>
    <a href="http://www.google.com/intl/zh-CN/">
    <img src="http://www.google.com/logos/Logo_40wht.gif" 
    border="0" alt="Google" align="absmiddle"></a>
    <input type=text name=q size=31 maxlength=255 value="">
    <input type=hidden name=ie value=GB2312>
    <input type=hidden name=oe value=GB2312>
    <input type=hidden name=hl value=zh-CN>
    <input type=submit name=btnG value="Google 搜索">
    </td></tr></table>
    </form>
    </center>
    <!-- Search Google -->
      

  4.   

    片断代码,供参考
    boolean   flag=false;   
              HttpURLConnection   httpConn=null;   
              FileInputStream   fin   =   null;   
              OutputStream   out   =   null;   
              InputStreamReader   isr   =   null;   
              BufferedReader   in   =   null;   
              try   {   
                  //与商户建立一个连接   
                  URL   url   =   new   URL(Url);   
                  //打开连接   
                  httpConn   =   (HttpURLConnection)   url.openConnection();   
                  fin   =   new   FileInputStream(xmlFile2Send);   
                  ByteArrayOutputStream   bout   =   new   ByteArrayOutputStream();   
                  copy(fin,   bout);   
                  byte[]   b   =   bout.toByteArray();   
                  httpConn.setRequestProperty("Content-Length",   String.valueOf(b.length));   
                  //以xml格式传送   
                  httpConn.setRequestProperty("Content-Type",   "text/xml;   charset=GB2312");   
                  httpConn.setRequestMethod("POST");   
                  httpConn.setDoOutput(true);   
                  httpConn.setDoInput(true);   
                  out   =   httpConn.getOutputStream();   
                  out.write(b);   
                  out.flush();   
                  httpConn.connect();   
                  //获取输入流   
                  isr   =   new   InputStreamReader(httpConn.getInputStream());   
                  in   =   new   BufferedReader(isr);   
                  StringBuffer   buf   =   new   StringBuffer();   
                  String   inputLine;   
                  while   (   (inputLine   =   in.readLine())   !=   null)   
                  {   
                      buf.append(inputLine);   
                  }   
        
                  if   (buf.toString().trim().equalsIgnoreCase("ok"))   {   
                      Tools.trace(buf.toString().trim());   
                      flag=true;   
                  }   
                  else   {   
                      flag=false;   
                  }   
        
              }catch   (MalformedURLException   ex)   {   
                  Tools.error(ex);   
              }   
              catch   (IOException   ex)   {   
                  Tools.error(ex);   
              }   
              finally   {   
                  //关闭操作   
                  Tools.closeBufferedReader(in);   
                  Tools.closeInputStreamReader(isr);   
                  Tools.closeOutputStream(out);   
                  Tools.closeFileInputStream(fin);   
                  Tools.closeHttpURLConnection(httpConn);   
              }   
              return   flag;   
          }   
      

  5.   

    楼上的你没理解对,我是在windows应用程序中直接向google发出请求,不是从网页中运行,然后请求的结果在浏览器中显示出来
      

  6.   

    那样的话你把得到的流保存成本地HTML,用浏览器打开。
      

  7.   

    lz的意思基本上不需要java帮忙了?直接调用windows的exeplorer.exe 执行?
    这样我觉得不是很好的方案
    能不能超出那楼主测试下就ok了阿
      

  8.   

    我也在考虑这么做,但是url的参数我不知道怎么传进去
    httpCon = (HttpURLConnection) url.openConnection();                        httpCon.setRequestProperty("q=","123456");
    我这样设完参数传回来的html代码竟然是google的首页,没有执行查询,这个url的参数应该怎么设阿,请hdhmail2000(禅剑飞雪)指点一下
      

  9.   

    我已经测试过了,直接用runtime执行的话肯定会有部分字符被截掉了
      

  10.   

    难得写,给你找了个完整的
    //postpackage com.dingo.sendurl;
    import  java.net.*;
    import java.io.InputStream;
    import java.io.BufferedReader;import java.io.InputStreamReader;public class send_url_post {
        private String urlStr;
        private URL url;
        private HttpURLConnection url_con;
        private String response_content;
        public void setUrlStr(String urlStr) {
            this.urlStr = urlStr;
        }    public String getResponse_content() {
            return response_content;
        }    private  void setResponse_content(String response_content) {
            this.response_content = response_content;
        }    public void send_url(String mobile_number){
            try{
                url = new url(/urlStr);
                url_con=(HttpURLConnection)url.openConnection();
                url_con.setRequestMethod("POST");
                url_con.setDoOutput(true);
                String param="action=mobile&mobile="+mobile_number;
                
                url_con.getOutputStream().write(param.getBytes());
                url_con.getOutputStream().flush();
                url_con.getOutputStream().close();            InputStream in= url_con.getInputStream();
                BufferedReader   rd = new BufferedReader(new InputStreamReader(in));
                StringBuilder tempStr=new StringBuilder();
                while(rd.read()!=-1){
                    tempStr.append(rd.readLine());
                }
               setResponse_content(new String(tempStr));
        } catch(Exception e){
                e.printStackTrace();
            }
            finally{
                if(url_con!=null)
                url_con.disconnect();        }
        }
    } //getpackage com.dingo.sendurl;import java.net.HttpURLConnection;
    import java.net.URL;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;public class send_url_get {
        private String urlStr;
        private URL url;
        private HttpURLConnection url_con;
        private String contentStr;
        public void setUrlStr(String urlStr) {
            this.urlStr = urlStr;
        }    public String getContentStr() {
            return contentStr;
        }    private void setContentStr(String contentStr) {
            this.contentStr = contentStr;
        }    public void send_url(){
            try{
                StringBuilder temp = new StringBuilder();
            url = new  url(/urlStr);         url_con= (HttpURLConnection)url.openConnection();
             url_con.setDoOutput(true);
             url_con.setRequestMethod("GET");         url_con.getOutputStream().flush();
             url_con.getOutputStream().close();
                InputStream in =url_con.getInputStream();
                BufferedReader rd = new BufferedReader(new InputStreamReader(in));
                while(rd.read()!=-1){
                    temp.append(rd.readLine());
                }
                setContentStr(new String (temp));    }       catch (Exception e){
                e.printStackTrace();
            }  finally{
                if(url_con!=null){
                    url_con.disconnect();
                }
            }
        }
    }
      

  11.   

    String strUrl = "http://www.google.com/search?q=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    URL objUrl = new URL(strUrl);你用这个方式定义URL试试,直接把参数带在里面。
      

  12.   

    或许你的url太长了,看下面的链接:http://support.microsoft.com/default.aspx?scid=kb;EN-US;q208427Maximum URL length is 2,083 characters in Internet ExplorerIf you are using the GET method, you are limited to a maximum of 2,048 characters, minus the number of characters in the actual path.
      

  13.   

    String strUrl = "http://www.google.com/search?q=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    URL objUrl = new URL(strUrl);这样返回411号错误
      

  14.   

    411 Length RequiredThe server refuses to accept the request without a defined Content- Length. The client MAY repeat the request if it adds a valid Content-Length header field containing the length of the message-body in the request message.