String host = "2shou.domain.cn";
Socket connection= new Socket(host, 80);
String GET = "GET / test.asp HTTP/1.0\r\n\r\n";
out.write(GET);我想要的资源是:http://2shou.domain.cn/test.asp
可实际上却得到的是:http://ip/test.asp (ip为2shou.domain.cn解析到的ip,即它实际上是把http://www.domain.cn/test.asp返回给我,这当然不行了,怎么来定位二级域名的资源呢)请问有什么办法可以解决这个问题!!!
Socket connection= new Socket(host, 80);
String GET = "GET / test.asp HTTP/1.0\r\n\r\n";
out.write(GET);我想要的资源是:http://2shou.domain.cn/test.asp
可实际上却得到的是:http://ip/test.asp (ip为2shou.domain.cn解析到的ip,即它实际上是把http://www.domain.cn/test.asp返回给我,这当然不行了,怎么来定位二级域名的资源呢)请问有什么办法可以解决这个问题!!!
with
http://www.douzhe.com/article/data/37/796.html
import java.net.*;
import java.io.*;public class Test {
public static void main(String[] args) throws Exception{
URL url = new URL("http://sports.163.com");
URLConnection uc = url.openConnection();
InputStream ins = uc.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(ins));
String s = br.readLine();
while(s!=null) {
System.out.println(s);
s = br.readLine();
}
}
}
///////////////////////
这是刚刚写的一个程序,希望有用,URLConection封装了对Socket的底层操作
能不能满足要求
1。如何处理编码的问题?得到的返回信息不能识别中文
2。怎么向URL传递参数(包括post和get类型的参数)
2.需要向url传递的参数,直接拼接在url上就可以了,就象你在IE的地址栏输入的一样。