请问如何实现访问带参数的URL地址?直接访问老是打不开,例如如下:
URL hp=new URL("http://www.baidu.com/");
这样就可以访问,没有问题,但在URL地址多加一个参数,如下:
URL hp=new URL("http://www.baidu.com/s?wd=您好");
这样就访问不了,真是奇怪。请问该如何解决,请例出具体代码,谢谢!
URL hp=new URL("http://www.baidu.com/");
这样就可以访问,没有问题,但在URL地址多加一个参数,如下:
URL hp=new URL("http://www.baidu.com/s?wd=您好");
这样就访问不了,真是奇怪。请问该如何解决,请例出具体代码,谢谢!
我只能说哈这一个表示.URL hp=new URL("http://www.baidu.com/s?wd=您好");
http://www.baidu.com/s代表的是实际存在的地址或路径,而加了?后面的就是有条件的请求,如果WEB服务器无法满足你的请求条件,或是受限访问等,你就访问不了.
URL hp=new URL("http://www.baidu.com/s?wd=您好");
URLConnection conn = hp.openConnection();
StringBuffer sb = new StringBuffer();
InputStream is = conn.getInputStream();
java.io.BufferedReader in = new BufferedReader(new InputStreamReader(is)); String line = "";
while ( (line = in.readLine()) != null) {
sb.append(line);
sb.append("\n");
}
System.out.println("content="+sb.toString());
都可以显示的啊
import java.io.*;
import java.util.Date;class UCDEMO
{
public static void main(String args[]) throws Exception
{
int c;
URL hp=new URL("http://www.baidu.com/s?wd=你好");URLConnection hpCon=hp.openConnection();
int len=hpCon.getContentLength();
System.out.println("Content-Length:"+len);
if(len>0){
System.out.println("=========content====");
InputStream input=hpCon.getInputStream();
int i=len;
while(((c=input.read())!=-1)&&(--i>0)){
if(c>128){
System.out.print(c);
}
System.out.print((char)c);
}
input.close();
}else{
System.out.println("No content available");
}}
}我是用这段代码,得不到内容!