问题:我使用Java给 www.baidu.com 分别发送http请求和https请求,得到了一样的结果,为什么?
结果:<html><head> <script> location.replace(location.href.replace("https://","http://")); </script></head><body> <noscript><meta http-equiv="refresh" content="0;url=http://www.baidu.com/"></noscript></body></html>
发送请求的代码:
URL Url = new URL("https://www.baidu.com/ "); //URL Url = new URL("http://www.baidu.com/ ");
URLConnection connection;
if(Url.getProtocol().equals("http"))
connection = (HttpURLConnection)Url.openConnection();
else if(Url.getProtocol().equals("https"))
connection = (HttpsURLConnection)Url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String received = "";
String s;
while((s=in.readLine())!=null)
received+=s;
System.out.println(received);
ps.同样的代码,给https://msdn.microsoft.com发送请求,可以获取网页的内容。
------解决思路----------------------
每个网站处理方式不一样。百度发现是HTTP,重定向用HTTPS。