Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 尝试使用原始套接字发送GET请求时获取301_Java_Sockets_Http - Fatal编程技术网

Java 尝试使用原始套接字发送GET请求时获取301

Java 尝试使用原始套接字发送GET请求时获取301,java,sockets,http,Java,Sockets,Http,为什么我尝试访问的每个URL都会得到301?我只是想用原始的插座作为练习!我在下面列出了回复。堆栈溢出使我键入更多的单词,因为我的响应主要是代码。这里还有一些词 Socket s = new Socket(InetAddress.getByName("stackoverflow.com"), 80); PrintWriter pw = new PrintWriter(s.getOutputStream()); pw.println("GET / HTTP/1.1\r");

为什么我尝试访问的每个URL都会得到301?我只是想用原始的插座作为练习!我在下面列出了回复。堆栈溢出使我键入更多的单词,因为我的响应主要是代码。这里还有一些词

    Socket s = new Socket(InetAddress.getByName("stackoverflow.com"), 80);
    PrintWriter pw = new PrintWriter(s.getOutputStream());
    pw.println("GET / HTTP/1.1\r");
    pw.println("Host: stackoverflow.com\r");
    pw.println("\r");

    pw.flush();

    BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
    String t;
    while ((t = br.readLine()) != null)
        System.out.println(t);
    br.close();

HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=utf-8
Location: https://stackoverflow.com/
X-Request-Guid: 5d0b1d72-5b10-4aa2-a563-4fd3d6b155cb
Content-Security-Policy: upgrade-insecure-requests
Content-Length: 143
Accept-Ranges: bytes
Date: Mon, 20 Aug 2018 06:19:15 GMT
Via: 1.1 varnish
Connection: keep-alive
X-Served-By: cache-dfw18637-DFW
X-Cache: MISS
X-Cache-Hits: 0
X-Timer: S1534745955.491886,VS0,VE37
Vary: Fastly-SSL
X-DNS-Prefetch-Control: off
Set-Cookie: prov=0bf5c623-b16b-d4b6-e822-504daf42c16e; 
domain=.stackoverflow.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; 
path=/; HttpOnly

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="https://stackoverflow.com/">here</a>.</h2>
</body></html>
sockets=newsocket(InetAddress.getByName(“stackoverflow.com”),80);
PrintWriter pw=新的PrintWriter(s.getOutputStream());
println(“GET/HTTP/1.1\r”);
println(“主机:stackoverflow.com\r”);
pw.println(“\r”);
pw.flush();
BufferedReader br=新的BufferedReader(新的InputStreamReader(s.getInputStream());
字符串t;
而((t=br.readLine())!=null)
系统输出打印ln(t);
br.close();
HTTP/1.1 301永久移动
内容类型:text/html;字符集=utf-8
地点:https://stackoverflow.com/
X-Request-Guid:5d0b1d72-5b10-4aa2-a563-4fd3d6b155cb
内容安全策略:升级不安全的请求
内容长度:143
接受范围:字节
日期:2018年8月20日星期一06:19:15 GMT
通孔:1.1清漆
连接:保持活力
X服务方:cache-dfw18637-DFW
X-Cache:小姐
X缓存命中率:0
X定时器:S1534745955.491886,VS0,VE37
变化:快速SSL
X-DNS-预取-控制:关闭
设置Cookie:prov=0bf5c623-b16b-d4b6-e822-504daf42c16e;
domain=.stackoverflow.com;expires=周五,2055年1月1日00:00:00 GMT;
路径=/;HttpOnly
移动的对象
对象移动到。

HTTP服务器希望重定向客户端以使用HTTPS。 如今,很难找到知名的HTTP服务器,但它不能做到这一点

例如,试试“jquery.com”,它不会重定向到HTTPS

顺便说一句:“原始套接字”不是TCP套接字的正确术语。
通常术语“原始套接字”用于原始IP套接字

HTTP服务器希望重定向客户端以使用HTTPS。 如今,很难找到知名的HTTP服务器,但它不能做到这一点

例如,试试“jquery.com”,它不会重定向到HTTPS

顺便说一句:“原始套接字”不是TCP套接字的正确术语。 通常术语“原始套接字”用于原始IP套接字