来自服务器的文件意外结束,但文件通过浏览器正确下载

时间:2015-12-15 11:32:34

标签: java inputstream

我有一项服务允许我从服务器下载PDF文件。发送请求时,文件会立即生成。

当我尝试通过浏览器打开URL时,正确下载了PDF。当我尝试以编程方式获取文件时,我得到以下异常:

java.net.SocketException: Unexpected end of file from server
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:792)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:789)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1536)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
    at java.net.URL.openStream(URL.java:1038)

我下载文件的代码是:

public void download(String urlStr, String fileName) {
    URL url = null;
    try {
        url = new URL(urlStr);
    } catch (MalformedURLException e) {
        e.printStackTrace();
        throw new BatException(e.getMessage());
    }

    InputStream in = null;
    try {
        in = url.openStream();
        Files.copy(in, Paths.get(fileName), StandardCopyOption.REPLACE_EXISTING);
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
        throw new BatException(e.getMessage());
    }

如何管理此问题?

====编辑 Wireshark日志(公共IP替换为xxx.xxx.xxx.xxx):

 No.     Time           Source                Destination           Protocol Length Info
   8281 69.263332000   192.168.1.103         xxx.xxx.xxx.xxx           TCP      76     43978→3000 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=16407907 TSecr=0 WS=128

Frame 8281: 76 bytes on wire (608 bits), 76 bytes captured (608 bits) on interface 0
Linux cooked capture
Internet Protocol Version 4, Src: 192.168.1.103 (192.168.1.103), Dst: xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)
Transmission Control Protocol, Src Port: 43978 (43978), Dst Port: 3000 (3000), Seq: 0, Len: 0

0000  00 04 00 01 00 06 c0 18 85 6a 3d 39 64 6f 08 00   .........j=9do..
0010  45 00 00 3c 58 69 40 00 40 06 1f 2c c0 a8 01 67   E..<Xi@.@..,...g
0020  b9 06 48 11 ab ca 0b b8 0b a0 05 0a 00 00 00 00   ..H.............
0030  a0 02 72 10 ec 3e 00 00 02 04 05 b4 04 02 08 0a   ..r..>..........
0040  00 fa 5d 63 00 00 00 00 01 03 03 07               ..]c........

No.     Time           Source                Destination           Protocol Length Info
   8283 69.305333000   xxx.xxx.xxx.xxx           192.168.1.103         TCP      76     3000→43978 [SYN, ACK] Seq=0 Ack=1 Win=14480 Len=0 MSS=1440 SACK_PERM=1 TSval=536967854 TSecr=16407907 WS=128

Frame 8283: 76 bytes on wire (608 bits), 76 bytes captured (608 bits) on interface 0
Linux cooked capture
Internet Protocol Version 4, Src: xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx), Dst: 192.168.1.103 (192.168.1.103)
Transmission Control Protocol, Src Port: 3000 (3000), Dst Port: 43978 (43978), Seq: 0, Ack: 1, Len: 0

0000  00 00 00 01 00 06 30 b5 c2 fe 5d 6b 38 32 08 00   ......0...]k82..
0010  45 00 00 3c 00 00 40 00 35 06 82 95 b9 06 48 11   E..<..@.5.....H.
0020  c0 a8 01 67 0b b8 ab ca b6 45 6a 4c 0b a0 05 0b   ...g.....EjL....
0030  a0 12 38 90 6a 80 00 00 02 04 05 a0 04 02 08 0a   ..8.j...........
0040  20 01 7a ae 00 fa 5d 63 01 03 03 07                .z...]c....

No.     Time           Source                Destination           Protocol Length Info
   8284 69.305372000   192.168.1.103         xxx.xxx.xxx.xxx           TCP      68     43978→3000 [ACK] Seq=1 Ack=1 Win=29312 Len=0 TSval=16407918 TSecr=536967854

Frame 8284: 68 bytes on wire (544 bits), 68 bytes captured (544 bits) on interface 0
Linux cooked capture
Internet Protocol Version 4, Src: 192.168.1.103 (192.168.1.103), Dst: xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)
Transmission Control Protocol, Src Port: 43978 (43978), Dst Port: 3000 (3000), Seq: 1, Ack: 1, Len: 0

0000  00 04 00 01 00 06 c0 18 85 6a 3d 39 35 2e 08 00   .........j=95...
0010  45 00 00 34 58 6a 40 00 40 06 1f 33 c0 a8 01 67   E..4Xj@.@..3...g
0020  b9 06 48 11 ab ca 0b b8 0b a0 05 0b b6 45 6a 4d   ..H..........EjM
0030  80 10 00 e5 d0 d8 00 00 01 01 08 0a 00 fa 5d 6e   ..............]n
0040  20 01 7a ae                                        .z.

No.     Time           Source                Destination           Protocol Length Info
   8285 69.306102000   192.168.1.103         xxx.xxx.xxx.xxx           HTTP     336    GET /pdf/Nuovo_Contratto 2015/100000 HTTP/1.1 

Frame 8285: 336 bytes on wire (2688 bits), 336 bytes captured (2688 bits) on interface 0
Linux cooked capture
Internet Protocol Version 4, Src: 192.168.1.103 (192.168.1.103), Dst: xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)
Transmission Control Protocol, Src Port: 43978 (43978), Dst Port: 3000 (3000), Seq: 1, Ack: 1, Len: 268
Hypertext Transfer Protocol

0000  00 04 00 01 00 06 c0 18 85 6a 3d 39 64 00 08 00   .........j=9d...
0010  45 00 01 40 58 6b 40 00 40 06 1e 26 c0 a8 01 67   E..@Xk@.@..&...g
0020  b9 06 48 11 ab ca 0b b8 0b a0 05 0b b6 45 6a 4d   ..H..........EjM
0030  80 18 00 e5 d6 40 00 00 01 01 08 0a 00 fa 5d 6e   .....@........]n
0040  20 01 7a ae 47 45 54 20 2f 70 64 66 2f 4e 75 6f    .z.GET /pdf/Nuo
0050  76 6f 5f 43 6f 6e 74 72 61 74 74 6f 20 32 30 31   vo_Contratto 201
0060  35 2f 31 30 30 30 30 30 20 48 54 54 50 2f 31 2e   5/100000 HTTP/1.
0070  31 0d 0a 55 73 65 72 2d 41 67 65 6e 74 3a 20 4d   1..User-Agent: M
0080  6f 7a 69 6c 6c 61 2f 35 2e 30 20 28 4d 61 63 69   ozilla/5.0 (Maci
0090  6e 74 6f 73 68 3b 20 55 3b 20 49 6e 74 65 6c 20   ntosh; U; Intel 
00a0  4d 61 63 20 4f 53 20 58 20 31 30 2e 34 3b 20 65   Mac OS X 10.4; e
00b0  6e 2d 55 53 3b 20 72 76 3a 31 2e 39 2e 32 2e 32   n-US; rv:1.9.2.2
00c0  29 20 47 65 63 6b 6f 2f 32 30 31 30 30 33 31 36   ) Gecko/20100316
00d0  20 46 69 72 65 66 6f 78 2f 33 2e 36 2e 32 0d 0a    Firefox/3.6.2..
00e0  48 6f 73 74 3a 20 31 38 35 2e 36 2e 37 32 2e 31   Host: xxx.xxx.xxx.xxx
00f0  37 3a 33 30 30 30 0d 0a 41 63 63 65 70 74 3a 20   7:3000..Accept: 
0100  74 65 78 74 2f 68 74 6d 6c 2c 20 69 6d 61 67 65   text/html, image
0110  2f 67 69 66 2c 20 69 6d 61 67 65 2f 6a 70 65 67   /gif, image/jpeg
0120  2c 20 2a 3b 20 71 3d 2e 32 2c 20 2a 2f 2a 3b 20   , *; q=.2, */ *; 
0130  71 3d 2e 32 0d 0a 43 6f 6e 6e 65 63 74 69 6f 6e   q=.2..Connection
0140  3a 20 6b 65 65 70 2d 61 6c 69 76 65 0d 0a 0d 0a   : keep-alive....

No.     Time           Source                Destination           Protocol Length Info
   8286 69.350774000   xxx.xxx.xxx.xxx           192.168.1.103         TCP      68     3000→43978 [ACK] Seq=1 Ack=269 Win=15616 Len=0 TSval=536967898 TSecr=16407918

Frame 8286: 68 bytes on wire (544 bits), 68 bytes captured (544 bits) on interface 0
Linux cooked capture
Internet Protocol Version 4, Src: xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx), Dst: 192.168.1.103 (192.168.1.103)
Transmission Control Protocol, Src Port: 3000 (3000), Dst Port: 43978 (43978), Seq: 1, Ack: 269, Len: 0

0000  00 00 00 01 00 06 30 b5 c2 fe 5d 6b 63 4d 08 00   ......0...]kcM..
0010  45 00 00 34 10 9b 40 00 35 06 72 02 b9 06 48 11   E..4..@.5.r...H.
0020  c0 a8 01 67 0b b8 ab ca b6 45 6a 4d 0b a0 06 17   ...g.....EjM....
0030  80 10 00 7a d0 0b 00 00 01 01 08 0a 20 01 7a da   ...z........ .z.
0040  00 fa 5d 6e                                       ..]n

No.     Time           Source                Destination           Protocol Length Info
   8287 69.351267000   xxx.xxx.xxx.xxx           192.168.1.103         TCP      68     3000→43978 [FIN, ACK] Seq=1 Ack=269 Win=15616 Len=0 TSval=536967899 TSecr=16407918

Frame 8287: 68 bytes on wire (544 bits), 68 bytes captured (544 bits) on interface 0
Linux cooked capture
Internet Protocol Version 4, Src: xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx), Dst: 192.168.1.103 (192.168.1.103)
Transmission Control Protocol, Src Port: 3000 (3000), Dst Port: 43978 (43978), Seq: 1, Ack: 269, Len: 0

0000  00 00 00 01 00 06 30 b5 c2 fe 5d 6b 31 2d 08 00   ......0...]k1-..
0010  45 00 00 34 10 9c 40 00 35 06 72 01 b9 06 48 11   E..4..@.5.r...H.
0020  c0 a8 01 67 0b b8 ab ca b6 45 6a 4d 0b a0 06 17   ...g.....EjM....
0030  80 11 00 7a d0 09 00 00 01 01 08 0a 20 01 7a db   ...z........ .z.
0040  00 fa 5d 6e                                       ..]n

No.     Time           Source                Destination           Protocol Length Info
   8288 69.351414000   192.168.1.103         xxx.xxx.xxx.xxx           TCP      68     43978→3000 [FIN, ACK] Seq=269 Ack=2 Win=29312 Len=0 TSval=16407929 TSecr=536967899

Frame 8288: 68 bytes on wire (544 bits), 68 bytes captured (544 bits) on interface 0
Linux cooked capture
Internet Protocol Version 4, Src: 192.168.1.103 (192.168.1.103), Dst: xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)
Transmission Control Protocol, Src Port: 43978 (43978), Dst Port: 3000 (3000), Seq: 269, Ack: 2, Len: 0

0000  00 04 00 01 00 06 c0 18 85 6a 3d 39 2b 76 08 00   .........j=9+v..
0010  45 00 00 34 58 6c 40 00 40 06 1f 31 c0 a8 01 67   E..4Xl@.@..1...g
0020  b9 06 48 11 ab ca 0b b8 0b a0 06 17 b6 45 6a 4e   ..H..........EjN
0030  80 11 00 e5 cf 92 00 00 01 01 08 0a 00 fa 5d 79   ..............]y
0040  20 01 7a db                                        .z.

No.     Time           Source                Destination           Protocol Length Info
   8289 69.351667000   192.168.1.103         xxx.xxx.xxx.xxx           TCP      76     43979→3000 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=16407929 TSecr=0 WS=128

Frame 8289: 76 bytes on wire (608 bits), 76 bytes captured (608 bits) on interface 0
Linux cooked capture
Internet Protocol Version 4, Src: 192.168.1.103 (192.168.1.103), Dst: xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)
Transmission Control Protocol, Src Port: 43979 (43979), Dst Port: 3000 (3000), Seq: 0, Len: 0

0000  00 04 00 01 00 06 c0 18 85 6a 3d 39 49 43 08 00   .........j=9IC..
0010  45 00 00 3c 5c 88 40 00 40 06 1b 0d c0 a8 01 67   E..<\.@.@......g
0020  b9 06 48 11 ab cb 0b b8 9f e5 01 f1 00 00 00 00   ..H.............
0030  a0 02 72 10 5a fb 00 00 02 04 05 b4 04 02 08 0a   ..r.Z...........
0040  00 fa 5d 79 00 00 00 00 01 03 03 07               ..]y........

No.     Time           Source                Destination           Protocol Length Info
   8290 69.392620000   xxx.xxx.xxx.xxx           192.168.1.103         TCP      68     3000→43978 [ACK] Seq=2 Ack=270 Win=15616 Len=0 TSval=536967941 TSecr=16407929

Frame 8290: 68 bytes on wire (544 bits), 68 bytes captured (544 bits) on interface 0
Linux cooked capture
Internet Protocol Version 4, Src: xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx), Dst: 192.168.1.103 (192.168.1.103)
Transmission Control Protocol, Src Port: 3000 (3000), Dst Port: 43978 (43978), Seq: 2, Ack: 270, Len: 0

0000  00 00 00 01 00 06 30 b5 c2 fe 5d 6b 61 64 08 00   ......0...]kad..
0010  45 00 00 34 10 9d 40 00 35 06 72 00 b9 06 48 11   E..4..@.5.r...H.
0020  c0 a8 01 67 0b b8 ab ca b6 45 6a 4e 0b a0 06 18   ...g.....EjN....
0030  80 10 00 7a cf d3 00 00 01 01 08 0a 20 01 7b 05   ...z........ .{.
0040  00 fa 5d 79                                       ..]y

No.     Time           Source                Destination           Protocol Length Info
   8291 69.394883000   xxx.xxx.xxx.xxx           192.168.1.103         TCP      76     3000→43979 [SYN, ACK] Seq=0 Ack=1 Win=14480 Len=0 MSS=1440 SACK_PERM=1 TSval=536967943 TSecr=16407929 WS=128

Frame 8291: 76 bytes on wire (608 bits), 76 bytes captured (608 bits) on interface 0
Linux cooked capture
Internet Protocol Version 4, Src: xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx), Dst: 192.168.1.103 (192.168.1.103)
Transmission Control Protocol, Src Port: 3000 (3000), Dst Port: 43979 (43979), Seq: 0, Ack: 1, Len: 0

0000  00 00 00 01 00 06 30 b5 c2 fe 5d 6b 5a 36 08 00   ......0...]kZ6..
0010  45 00 00 3c 00 00 40 00 35 06 82 95 b9 06 48 11   E..<..@.5.....H.
0020  c0 a8 01 67 0b b8 ab cb e3 d6 50 64 9f e5 01 f2   ...g......Pd....
0030  a0 12 38 90 c5 3a 00 00 02 04 05 a0 04 02 08 0a   ..8..:..........
0040  20 01 7b 07 00 fa 5d 79 01 03 03 07                .{...]y....

No.     Time           Source                Destination           Protocol Length Info
   8292 69.394959000   192.168.1.103         xxx.xxx.xxx.xxx           TCP      68     43979→3000 [ACK] Seq=1 Ack=1 Win=29312 Len=0 TSval=16407940 TSecr=536967943

Frame 8292: 68 bytes on wire (544 bits), 68 bytes captured (544 bits) on interface 0
Linux cooked capture
Internet Protocol Version 4, Src: 192.168.1.103 (192.168.1.103), Dst: xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)
Transmission Control Protocol, Src Port: 43979 (43979), Dst Port: 3000 (3000), Seq: 1, Ack: 1, Len: 0

0000  00 04 00 01 00 06 c0 18 85 6a 3d 39 00 00 08 00   .........j=9....
0010  45 00 00 34 5c 89 40 00 40 06 1b 14 c0 a8 01 67   E..4\.@.@......g
0020  b9 06 48 11 ab cb 0b b8 9f e5 01 f2 e3 d6 50 65   ..H...........Pe
0030  80 10 00 e5 2b 93 00 00 01 01 08 0a 00 fa 5d 84   ....+.........].
0040  20 01 7b 07                                        .{.

No.     Time           Source                Destination           Protocol Length Info
   8293 69.395532000   192.168.1.103         xxx.xxx.xxx.xxx           HTTP     336    GET /pdf/Nuovo_Contratto 2015/100000 HTTP/1.1 

Frame 8293: 336 bytes on wire (2688 bits), 336 bytes captured (2688 bits) on interface 0
Linux cooked capture
Internet Protocol Version 4, Src: 192.168.1.103 (192.168.1.103), Dst: xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)
Transmission Control Protocol, Src Port: 43979 (43979), Dst Port: 3000 (3000), Seq: 1, Ack: 1, Len: 268
Hypertext Transfer Protocol

0000  00 04 00 01 00 06 c0 18 85 6a 3d 39 49 a4 08 00   .........j=9I...
0010  45 00 01 40 5c 8a 40 00 40 06 1a 07 c0 a8 01 67   E..@\.@.@......g
0020  b9 06 48 11 ab cb 0b b8 9f e5 01 f2 e3 d6 50 65   ..H...........Pe
0030  80 18 00 e5 30 fb 00 00 01 01 08 0a 00 fa 5d 84   ....0.........].
0040  20 01 7b 07 47 45 54 20 2f 70 64 66 2f 4e 75 6f    .{.GET /pdf/Nuo
0050  76 6f 5f 43 6f 6e 74 72 61 74 74 6f 20 32 30 31   vo_Contratto 201
0060  35 2f 31 30 30 30 30 30 20 48 54 54 50 2f 31 2e   5/100000 HTTP/1.
0070  31 0d 0a 55 73 65 72 2d 41 67 65 6e 74 3a 20 4d   1..User-Agent: M
0080  6f 7a 69 6c 6c 61 2f 35 2e 30 20 28 4d 61 63 69   ozilla/5.0 (Maci
0090  6e 74 6f 73 68 3b 20 55 3b 20 49 6e 74 65 6c 20   ntosh; U; Intel 
00a0  4d 61 63 20 4f 53 20 58 20 31 30 2e 34 3b 20 65   Mac OS X 10.4; e
00b0  6e 2d 55 53 3b 20 72 76 3a 31 2e 39 2e 32 2e 32   n-US; rv:1.9.2.2
00c0  29 20 47 65 63 6b 6f 2f 32 30 31 30 30 33 31 36   ) Gecko/20100316
00d0  20 46 69 72 65 66 6f 78 2f 33 2e 36 2e 32 0d 0a    Firefox/3.6.2..
00e0  48 6f 73 74 3a 20 31 38 35 2e 36 2e 37 32 2e 31   Host: xxx.xxx.xxx.xxx
00f0  37 3a 33 30 30 30 0d 0a 41 63 63 65 70 74 3a 20   7:3000..Accept: 
0100  74 65 78 74 2f 68 74 6d 6c 2c 20 69 6d 61 67 65   text/html, image
0110  2f 67 69 66 2c 20 69 6d 61 67 65 2f 6a 70 65 67   /gif, image/jpeg
0120  2c 20 2a 3b 20 71 3d 2e 32 2c 20 2a 2f 2a 3b 20   , *; q=.2, */ *; 
0130  71 3d 2e 32 0d 0a 43 6f 6e 6e 65 63 74 69 6f 6e   q=.2..Connection
0140  3a 20 6b 65 65 70 2d 61 6c 69 76 65 0d 0a 0d 0a   : keep-alive....

No.     Time           Source                Destination           Protocol Length Info
   8294 69.441757000   xxx.xxx.xxx.xxx           192.168.1.103         TCP      68     3000→43979 [ACK] Seq=1 Ack=269 Win=15616 Len=0 TSval=536967990 TSecr=16407940

Frame 8294: 68 bytes on wire (544 bits), 68 bytes captured (544 bits) on interface 0
Linux cooked capture
Internet Protocol Version 4, Src: xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx), Dst: 192.168.1.103 (192.168.1.103)
Transmission Control Protocol, Src Port: 3000 (3000), Dst Port: 43979 (43979), Seq: 1, Ack: 269, Len: 0

0000  00 00 00 01 00 06 30 b5 c2 fe 5d 6b 00 00 08 00   ......0...]k....
0010  45 00 00 34 2b 57 40 00 35 06 57 46 b9 06 48 11   E..4+W@.5.WF..H.
0020  c0 a8 01 67 0b b8 ab cb e3 d6 50 65 9f e5 02 fe   ...g......Pe....
0030  80 10 00 7a 2a c3 00 00 01 01 08 0a 20 01 7b 36   ...z*....... .{6
0040  00 fa 5d 84                                       ..].

No.     Time           Source                Destination           Protocol Length Info
   8295 69.442169000   xxx.xxx.xxx.xxx           192.168.1.103         TCP      68     3000→43979 [FIN, ACK] Seq=1 Ack=269 Win=15616 Len=0 TSval=536967990 TSecr=16407940

Frame 8295: 68 bytes on wire (544 bits), 68 bytes captured (544 bits) on interface 0
Linux cooked capture
Internet Protocol Version 4, Src: xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx), Dst: 192.168.1.103 (192.168.1.103)
Transmission Control Protocol, Src Port: 3000 (3000), Dst Port: 43979 (43979), Seq: 1, Ack: 269, Len: 0

0000  00 00 00 01 00 06 30 b5 c2 fe 5d 6b 00 00 08 00   ......0...]k....
0010  45 00 00 34 2b 58 40 00 35 06 57 45 b9 06 48 11   E..4+X@.5.WE..H.
0020  c0 a8 01 67 0b b8 ab cb e3 d6 50 65 9f e5 02 fe   ...g......Pe....
0030  80 11 00 7a 2a c2 00 00 01 01 08 0a 20 01 7b 36   ...z*....... .{6
0040  00 fa 5d 84                                       ..].

No.     Time           Source                Destination           Protocol Length Info
   8296 69.442313000   192.168.1.103         xxx.xxx.xxx.xxx           TCP      68     43979→3000 [FIN, ACK] Seq=269 Ack=2 Win=29312 Len=0 TSval=16407952 TSecr=536967990

Frame 8296: 68 bytes on wire (544 bits), 68 bytes captured (544 bits) on interface 0
Linux cooked capture
Internet Protocol Version 4, Src: 192.168.1.103 (192.168.1.103), Dst: xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)
Transmission Control Protocol, Src Port: 43979 (43979), Dst Port: 3000 (3000), Seq: 269, Ack: 2, Len: 0

0000  00 04 00 01 00 06 c0 18 85 6a 3d 39 76 61 08 00   .........j=9va..
0010  45 00 00 34 5c 8b 40 00 40 06 1b 12 c0 a8 01 67   E..4\.@.@......g
0020  b9 06 48 11 ab cb 0b b8 9f e5 02 fe e3 d6 50 66   ..H...........Pf
0030  80 11 00 e5 2a 4a 00 00 01 01 08 0a 00 fa 5d 90   ....*J........].
0040  20 01 7b 36                                        .{6

No.     Time           Source                Destination           Protocol Length Info
   8334 69.483458000   xxx.xxx.xxx.xxx           192.168.1.103         TCP      68     3000→43979 [ACK] Seq=2 Ack=270 Win=15616 Len=0 TSval=536968032 TSecr=16407952

Frame 8334: 68 bytes on wire (544 bits), 68 bytes captured (544 bits) on interface 0
Linux cooked capture
Internet Protocol Version 4, Src: xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx), Dst: 192.168.1.103 (192.168.1.103)
Transmission Control Protocol, Src Port: 3000 (3000), Dst Port: 43979 (43979), Seq: 2, Ack: 270, Len: 0

0000  00 00 00 01 00 06 30 b5 c2 fe 5d 6b 65 43 08 00   ......0...]keC..
0010  45 00 00 34 2b 59 40 00 35 06 57 44 b9 06 48 11   E..4+Y@.5.WD..H.
0020  c0 a8 01 67 0b b8 ab cb e3 d6 50 66 9f e5 02 ff   ...g......Pf....
0030  80 10 00 7a 2a 8b 00 00 01 01 08 0a 20 01 7b 60   ...z*....... .{`
0040  00 fa 5d 90                                       ..].

1 个答案:

答案 0 :(得分:0)

感谢Jon Skeet我发现这是标题问题。从浏览器构建的请求中复制的以下标头可以解决问题:

conn.addRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36");
            conn.addRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
            conn.addRequestProperty("Accept-Encoding", "gzip, deflate, sdch");
            conn.addRequestProperty("Accept-Language", "it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4");
            conn.addRequestProperty("Upgrade-Insecure-Requests", "1");