消息头为Transfer-Encoding:chunked时使用fiddler更改响应值,提示解码失败

本文详细介绍了在使用Fiddler工具修改HTTP响应值时遇到的net::err_invalid_chunked_encoding解码错误问题。当响应头采用Transfer-Encoding:chunked时,直接修改响应内容会导致长度不匹配,从而引发解码失败。文章提供了正确的解决方法,即在修改响应值的同时更新长度值,确保数据完整性和一致性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在使用fiddler更改服务端返回的值时候,在浏览器上解码失败net::err_invalid_chunked_encoding ,查了许久,是因为改发返回值的时候,长度也发生了变化,所以需要将长度值也改了才能成功
只更改响应值:

浏览器提示解码失败,net::err_invalid_chunked_encoding
这里写图片描述
百度之后发现是因为消息头使用的是Transfer-Encoding:chunked,用另一种方式传送数据长度值
这里写图片描述
更改:
使用的是十六进制的方式传送长度数值,当我将11改成111时,长度发生了变化,所以需要将之前的bf改成c0,(bf和c0是十六进制形式,十进制分别为190和191)
这里写图片描述
浏览器解码成功:
这里写图片描述

为什么会查很久呢,因为自己没注意看响应数据前一行和最后一行的字符,以为是fiddler出现的乱码,哈哈哈,深刻的教训
虽然这看起来是个小问题,但是出现这个问题后各种方式百度,又自己调试才找到原因得到这个答案
Transfer-Encoding:chunked参考资料https://www.cnblogs.com/xuehaoyue/p/6639029.html

日志:[TASK] ====== CONTINUOUS DOWNLOAD STARTED ====== [INFO] Devices: 8 | Save path: F:/GKD/ [PROCESS] Device: GK2025040001 | Date: 2025-07-01 [DEBUG] Time Parameters: Original Local: 2025-07-01T00:00 - 2025-07-01T23:59:59 Converted Server: 2025-07-01 00:00:00 - 2025-07-01 23:59:59 Raw Time: 2025-07-01 00:00:00 & 2025-07-01 23:59:59 [DEBUG] Final request URL: http://nyzbwlw.com/situation/http/device/bug/getBugData?deviceCode=GK2025040001&startTime=2025-07-01%2000:00:00&endTime=2025-07-01%2023:59:59&size=1000&t=1754026969103 2025-08-01 13:42:49 [Thread-1] DEBUG o.s.web.client.RestTemplate - HTTP GET http://nyzbwlw.com/situation/http/device/bug/getBugData?deviceCode=GK2025040001&startTime=2025-07-01%252000:00:00&endTime=2025-07-01%252023:59:59&size=1000&t=1754026969103 2025-08-01 13:42:49 [Thread-1] DEBUG o.s.web.client.RestTemplate - Accept=[text/plain, application/json, application/*+json, */*] 2025-08-01 13:42:49 [Thread-1] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: default 2025-08-01 13:42:49 [Thread-1] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context 2025-08-01 13:42:49 [Thread-1] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://nyzbwlw.com:80][total available: 0; route allocated: 0 of 2; total allocated: 0 of 20] 2025-08-01 13:42:49 [Thread-1] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {}->http://nyzbwlw.com:80][total available: 0; route allocated: 1 of 2; total allocated: 1 of 20] 2025-08-01 13:42:49 [Thread-1] DEBUG o.a.h.impl.execchain.MainClientExec - Opening connection {}->http://nyzbwlw.com:80 2025-08-01 13:42:49 [Thread-1] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to nyzbwlw.com/47.92.156.54:80 2025-08-01 13:42:49 [Thread-1] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connection established 192.168.2.4:62064<->47.92.156.54:80 2025-08-01 13:42:49 [Thread-1] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 15000 2025-08-01 13:42:49 [Thread-1] DEBUG o.a.h.impl.execchain.MainClientExec - Executing request GET /situation/http/device/bug/getBugData?deviceCode=GK2025040001&startTime=2025-07-01%252000:00:00&endTime=2025-07-01%252023:59:59&size=1000&t=1754026969103 HTTP/1.1 2025-08-01 13:42:49 [Thread-1] DEBUG o.a.h.impl.execchain.MainClientExec - Target auth state: UNCHALLENGED 2025-08-01 13:42:49 [Thread-1] DEBUG o.a.h.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> GET /situation/http/device/bug/getBugData?deviceCode=GK2025040001&startTime=2025-07-01%252000:00:00&endTime=2025-07-01%252023:59:59&size=1000&t=1754026969103 HTTP/1.1 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept: application/json, text/plain, */* 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: keep-alive 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Referer: http://nyzbwlw.com/situation/ 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Origin: http://nyzbwlw.com 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Sec-Fetch-Dest: empty 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Sec-Fetch-Mode: cors 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Sec-Fetch-Site: same-origin 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: nyzbwlw.com 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "GET /situation/http/device/bug/getBugData?deviceCode=GK2025040001&startTime=2025-07-01%252000:00:00&endTime=2025-07-01%252023:59:59&size=1000&t=1754026969103 HTTP/1.1[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept: application/json, text/plain, */*[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: keep-alive[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Referer: http://nyzbwlw.com/situation/[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Origin: http://nyzbwlw.com[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Sec-Fetch-Dest: empty[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Sec-Fetch-Mode: cors[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Sec-Fetch-Site: same-origin[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: nyzbwlw.com[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 200 [\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Server: nginx/1.20.2[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Date: Fri, 01 Aug 2025 05:42:49 GMT[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Type: application/json;charset=UTF-8[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Transfer-Encoding: chunked[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Connection: keep-alive[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Access-Control-Allow-Credentials: true[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Access-Control-Allow-Origin: *[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Vary: Origin[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Access-Control-Expose-Headers: Set-Cookie[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Set-Cookie: JSESSIONID=852AF1576F877DE9C07BC6B516B6220A; Path=/situation; HttpOnly[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "41[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "{"msg":"[0xe6][0x93][0x8d][0xe4][0xbd][0x9c][0xe6][0x88][0x90][0xe5][0x8a][0x9f][0xef][0xbc][0x81]","code":100,"data":{"count":0,"list":[]}}[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "0[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]" 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 200 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Server: nginx/1.20.2 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Date: Fri, 01 Aug 2025 05:42:49 GMT 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Type: application/json;charset=UTF-8 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Transfer-Encoding: chunked 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Connection: keep-alive 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Access-Control-Allow-Credentials: true 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Access-Control-Allow-Origin: * 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Vary: Origin 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Access-Control-Expose-Headers: Set-Cookie 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS 2025-08-01 13:42:49 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Set-Cookie: JSESSIONID=852AF1576F877DE9C07BC6B516B6220A; Path=/situation; HttpOnly 2025-08-01 13:42:49 [Thread-1] DEBUG o.a.h.impl.execchain.MainClientExec - Connection can be kept alive indefinitely 2025-08-01 13:42:49 [Thread-1] DEBUG o.a.h.c.p.ResponseProcessCookies - Cookie accepted [JSESSIONID="852AF1576F877DE9C07BC6B516B6220A", version:0, domain:nyzbwlw.com, path:/situation, expiry:null] 2025-08-01 13:42:49 [Thread-1] DEBUG o.s.web.client.RestTemplate - Response 200 OK 2025-08-01 13:42:49 [Thread-1] DEBUG o.s.web.client.RestTemplate - Reading to [java.lang.String] as "application/json;charset=UTF-8" 2025-08-01 13:42:49 [Thread-1] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection [id: 0][route: {}->http://nyzbwlw.com:80] can be kept alive indefinitely 2025-08-01 13:42:49 [Thread-1] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 0 2025-08-01 13:42:49 [Thread-1] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {}->http://nyzbwlw.com:80][total available: 1; route allocated: 1 of 2; total allocated: 1 of 20] [COOKIE] Saved session cookie: JSESSIONID [DEBUG] Response Status: 200 OK [DEBUG] Raw API response snippet: {"msg":"操作成功!","code":100,"data":{"count":0,"list":[]}} [DEBUG] Parsed API response code: 100 | message: 操作成功! [DEBUG] Found 0 valid image entries [RETRY] Retrying in 2000 ms (attempt 2/3) [DEBUG] Time Parameters: Original Local: 2025-07-01T00:00 - 2025-07-01T23:59:59 Converted Server: 2025-07-01 00:00:00 - 2025-07-01 23:59:59 Raw Time: 2025-07-01 00:00:00 & 2025-07-01 23:59:59 [DEBUG] Final request URL: http://nyzbwlw.com/situation/http/device/bug/getBugData?deviceCode=GK2025040001&startTime=2025-07-01%2000:00:00&endTime=2025-07-01%2023:59:59&size=1000&t=1754026971579 [DEBUG] Sending cookies: JSESSIONID=852AF1576F877DE9C07BC6B516B6220A 2025-08-01 13:42:51 [Thread-1] DEBUG o.s.web.client.RestTemplate - HTTP GET http://nyzbwlw.com/situation/http/device/bug/getBugData?deviceCode=GK2025040001&startTime=2025-07-01%252000:00:00&endTime=2025-07-01%252023:59:59&size=1000&t=1754026971579 2025-08-01 13:42:51 [Thread-1] DEBUG o.s.web.client.RestTemplate - Accept=[text/plain, application/json, application/*+json, */*] 2025-08-01 13:42:51 [Thread-1] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: default 2025-08-01 13:42:51 [Thread-1] DEBUG o.a.h.c.protocol.RequestAddCookies - Cookie [version: 0][name: JSESSIONID][value: 852AF1576F877DE9C07BC6B516B6220A][domain: nyzbwlw.com][path: /situation][expiry: null] match [nyzbwlw.com:80/situation/http/device/bug/getBugData] 2025-08-01 13:42:51 [Thread-1] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context 2025-08-01 13:42:51 [Thread-1] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://nyzbwlw.com:80][total available: 1; route allocated: 1 of 2; total allocated: 1 of 20] 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "[read] I/O error: Read timed out" 2025-08-01 13:42:51 [Thread-1] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {}->http://nyzbwlw.com:80][total available: 0; route allocated: 1 of 2; total allocated: 1 of 20] 2025-08-01 13:42:51 [Thread-1] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 0 2025-08-01 13:42:51 [Thread-1] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 15000 2025-08-01 13:42:51 [Thread-1] DEBUG o.a.h.impl.execchain.MainClientExec - Executing request GET /situation/http/device/bug/getBugData?deviceCode=GK2025040001&startTime=2025-07-01%252000:00:00&endTime=2025-07-01%252023:59:59&size=1000&t=1754026971579 HTTP/1.1 2025-08-01 13:42:51 [Thread-1] DEBUG o.a.h.impl.execchain.MainClientExec - Target auth state: UNCHALLENGED 2025-08-01 13:42:51 [Thread-1] DEBUG o.a.h.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> GET /situation/http/device/bug/getBugData?deviceCode=GK2025040001&startTime=2025-07-01%252000:00:00&endTime=2025-07-01%252023:59:59&size=1000&t=1754026971579 HTTP/1.1 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept: application/json, text/plain, */* 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: keep-alive 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Referer: http://nyzbwlw.com/situation/ 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Origin: http://nyzbwlw.com 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Sec-Fetch-Dest: empty 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Sec-Fetch-Mode: cors 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Sec-Fetch-Site: same-origin 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Cookie: JSESSIONID=852AF1576F877DE9C07BC6B516B6220A 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: nyzbwlw.com 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Cookie: JSESSIONID=852AF1576F877DE9C07BC6B516B6220A 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "GET /situation/http/device/bug/getBugData?deviceCode=GK2025040001&startTime=2025-07-01%252000:00:00&endTime=2025-07-01%252023:59:59&size=1000&t=1754026971579 HTTP/1.1[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept: application/json, text/plain, */*[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: keep-alive[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Referer: http://nyzbwlw.com/situation/[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Origin: http://nyzbwlw.com[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Sec-Fetch-Dest: empty[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Sec-Fetch-Mode: cors[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Sec-Fetch-Site: same-origin[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Cookie: JSESSIONID=852AF1576F877DE9C07BC6B516B6220A[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: nyzbwlw.com[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Cookie: JSESSIONID=852AF1576F877DE9C07BC6B516B6220A[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 200 [\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Server: nginx/1.20.2[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Date: Fri, 01 Aug 2025 05:42:51 GMT[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Type: application/json;charset=UTF-8[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Transfer-Encoding: chunked[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Connection: keep-alive[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Access-Control-Allow-Credentials: true[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Access-Control-Allow-Origin: *[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Vary: Origin[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Access-Control-Expose-Headers: Set-Cookie[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "41[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "{"msg":"[0xe6][0x93][0x8d][0xe4][0xbd][0x9c][0xe6][0x88][0x90][0xe5][0x8a][0x9f][0xef][0xbc][0x81]","code":100,"data":{"count":0,"list":[]}}[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "0[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]" 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 200 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Server: nginx/1.20.2 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Date: Fri, 01 Aug 2025 05:42:51 GMT 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Type: application/json;charset=UTF-8 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Transfer-Encoding: chunked 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Connection: keep-alive 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Access-Control-Allow-Credentials: true 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Access-Control-Allow-Origin: * 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Vary: Origin 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Access-Control-Expose-Headers: Set-Cookie 2025-08-01 13:42:51 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS 2025-08-01 13:42:51 [Thread-1] DEBUG o.a.h.impl.execchain.MainClientExec - Connection can be kept alive indefinitely 2025-08-01 13:42:51 [Thread-1] DEBUG o.s.web.client.RestTemplate - Response 200 OK 2025-08-01 13:42:51 [Thread-1] DEBUG o.s.web.client.RestTemplate - Reading to [java.lang.String] as "application/json;charset=UTF-8" 2025-08-01 13:42:51 [Thread-1] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection [id: 0][route: {}->http://nyzbwlw.com:80] can be kept alive indefinitely 2025-08-01 13:42:51 [Thread-1] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 0 2025-08-01 13:42:51 [Thread-1] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {}->http://nyzbwlw.com:80][total available: 1; route allocated: 1 of 2; total allocated: 1 of 20] [DEBUG] Response Status: 200 OK [DEBUG] Raw API response snippet: {"msg":"操作成功!","code":100,"data":{"count":0,"list":[]}} [DEBUG] Parsed API response code: 100 | message: 操作成功! [DEBUG] Found 0 valid image entries [RETRY] Retrying in 4000 ms (attempt 3/3) [DEBUG] Time Parameters: Original Local: 2025-07-01T00:00 - 2025-07-01T23:59:59 Converted Server: 2025-07-01 00:00:00 - 2025-07-01 23:59:59 Raw Time: 2025-07-01 00:00:00 & 2025-07-01 23:59:59 [DEBUG] Final request URL: http://nyzbwlw.com/situation/http/device/bug/getBugData?deviceCode=GK2025040001&startTime=2025-07-01%2000:00:00&endTime=2025-07-01%2023:59:59&size=1000&t=1754026975716 [DEBUG] Sending cookies: JSESSIONID=852AF1576F877DE9C07BC6B516B6220A 2025-08-01 13:42:55 [Thread-1] DEBUG o.s.web.client.RestTemplate - HTTP GET http://nyzbwlw.com/situation/http/device/bug/getBugData?deviceCode=GK2025040001&startTime=2025-07-01%252000:00:00&endTime=2025-07-01%252023:59:59&size=1000&t=1754026975716 2025-08-01 13:42:55 [Thread-1] DEBUG o.s.web.client.RestTemplate - Accept=[text/plain, application/json, application/*+json, */*] 2025-08-01 13:42:55 [Thread-1] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: default 2025-08-01 13:42:55 [Thread-1] DEBUG o.a.h.c.protocol.RequestAddCookies - Cookie [version: 0][name: JSESSIONID][value: 852AF1576F877DE9C07BC6B516B6220A][domain: nyzbwlw.com][path: /situation][expiry: null] match [nyzbwlw.com:80/situation/http/device/bug/getBugData] 2025-08-01 13:42:55 [Thread-1] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context 2025-08-01 13:42:55 [Thread-1] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://nyzbwlw.com:80][total available: 1; route allocated: 1 of 2; total allocated: 1 of 20] 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "[read] I/O error: Read timed out" 2025-08-01 13:42:55 [Thread-1] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {}->http://nyzbwlw.com:80][total available: 0; route allocated: 1 of 2; total allocated: 1 of 20] 2025-08-01 13:42:55 [Thread-1] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 0 2025-08-01 13:42:55 [Thread-1] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 15000 2025-08-01 13:42:55 [Thread-1] DEBUG o.a.h.impl.execchain.MainClientExec - Executing request GET /situation/http/device/bug/getBugData?deviceCode=GK2025040001&startTime=2025-07-01%252000:00:00&endTime=2025-07-01%252023:59:59&size=1000&t=1754026975716 HTTP/1.1 2025-08-01 13:42:55 [Thread-1] DEBUG o.a.h.impl.execchain.MainClientExec - Target auth state: UNCHALLENGED 2025-08-01 13:42:55 [Thread-1] DEBUG o.a.h.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> GET /situation/http/device/bug/getBugData?deviceCode=GK2025040001&startTime=2025-07-01%252000:00:00&endTime=2025-07-01%252023:59:59&size=1000&t=1754026975716 HTTP/1.1 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept: application/json, text/plain, */* 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: keep-alive 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Referer: http://nyzbwlw.com/situation/ 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Origin: http://nyzbwlw.com 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Sec-Fetch-Dest: empty 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Sec-Fetch-Mode: cors 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Sec-Fetch-Site: same-origin 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Cookie: JSESSIONID=852AF1576F877DE9C07BC6B516B6220A 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: nyzbwlw.com 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Cookie: JSESSIONID=852AF1576F877DE9C07BC6B516B6220A 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "GET /situation/http/device/bug/getBugData?deviceCode=GK2025040001&startTime=2025-07-01%252000:00:00&endTime=2025-07-01%252023:59:59&size=1000&t=1754026975716 HTTP/1.1[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept: application/json, text/plain, */*[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: keep-alive[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Referer: http://nyzbwlw.com/situation/[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Origin: http://nyzbwlw.com[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Sec-Fetch-Dest: empty[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Sec-Fetch-Mode: cors[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Sec-Fetch-Site: same-origin[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Cookie: JSESSIONID=852AF1576F877DE9C07BC6B516B6220A[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: nyzbwlw.com[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Cookie: JSESSIONID=852AF1576F877DE9C07BC6B516B6220A[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 200 [\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Server: nginx/1.20.2[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Date: Fri, 01 Aug 2025 05:42:55 GMT[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Type: application/json;charset=UTF-8[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Transfer-Encoding: chunked[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Connection: keep-alive[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Access-Control-Allow-Credentials: true[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Access-Control-Allow-Origin: *[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Vary: Origin[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Access-Control-Expose-Headers: Set-Cookie[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "41[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "{"msg":"[0xe6][0x93][0x8d][0xe4][0xbd][0x9c][0xe6][0x88][0x90][0xe5][0x8a][0x9f][0xef][0xbc][0x81]","code":100,"data":{"count":0,"list":[]}}[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "0[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]" 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 200 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Server: nginx/1.20.2 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Date: Fri, 01 Aug 2025 05:42:55 GMT 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Type: application/json;charset=UTF-8 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Transfer-Encoding: chunked 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Connection: keep-alive 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Access-Control-Allow-Credentials: true 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Access-Control-Allow-Origin: * 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Vary: Origin 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Access-Control-Expose-Headers: Set-Cookie 2025-08-01 13:42:55 [Thread-1] DEBUG org.apache.http.headers - http-outgoing-0 << Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS 2025-08-01 13:42:55 [Thread-1] DEBUG o.a.h.impl.execchain.MainClientExec - Connection can be kept alive indefinitely 2025-08-01 13:42:55 [Thread-1] DEBUG o.s.web.client.RestTemplate - Response 200 OK 2025-08-01 13:42:55 [Thread-1] DEBUG o.s.web.client.RestTemplate - Reading to [java.lang.String] as "application/json;charset=UTF-8" 2025-08-01 13:42:55 [Thread-1] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection [id: 0][route: {}->http://nyzbwlw.com:80] can be kept alive indefinitely 2025-08-01 13:42:55 [Thread-1] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 0 2025-08-01 13:42:55 [Thread-1] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {}->http://nyzbwlw.com:80][total available: 1; route allocated: 1 of 2; total allocated: 1 of 20] [DEBUG] Response Status: 200 OK [DEBUG] Raw API response snippet: {"msg":"操作成功!","code":100,"data":{"count":0,"list":[]}} [DEBUG] Parsed API response code: 100 | message: 操作成功! [DEBUG] Found 0 valid image entries [STATS] Device: GK2025040001 | Total: 0 | Success: 0 | Failed: 0 [RESULT] Device: GK2025040001 | Date: 2025-07-01 | Found: 0 | Downloaded: 0 | Failed: 0 代码:package com.example.service; import org.springframework.stereotype.Service; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.client.RestTemplate; import org.springframework.http.ResponseEntity; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.core.type.TypeReference; import java.util.*; import java.time.*; import java.time.format.DateTimeFormatter; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.io.IOException; import java.util.concurrent.ConcurrentHashMap; import javax.annotation.PostConstruct; import com.example.model.BugApiResponse; import com.example.model.BugResponseData; import com.example.model.BugImageInfo; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.net.InetAddress; import java.util.stream.Collectors; import org.springframework.web.util.UriComponentsBuilder; import java.net.URI; @Service public class BugImageDownloadService { private static final ZoneId SERVER_ZONE = ZoneId.of("Asia/Shanghai"); private static final String API_URL = "http://nyzbwlw.com/situation/http/device/bug/getBugData"; private static final DateTimeFormatter API_DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); private static final DateTimeFormatter FILE_DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd"); private static final DateTimeFormatter FILE_TIME_FORMAT = DateTimeFormatter.ofPattern("HH_mm_ss"); private final ConcurrentHashMap<String, LocalDateTime> deviceLastUpdateMap = new ConcurrentHashMap<>(); @Value("${bug.download.deviceCodes:GK2025040001,GK2025040002,GK2025040003,GK2025040004,GK2025040005,GK2025040006,GK2025040007,GK2025040008}") private List<String> deviceCodes; private final Map<String, String> cookies = new ConcurrentHashMap<>(); // 存储每个设备的下一个处理日期 private final ConcurrentHashMap<String, LocalDate> deviceNextDateMap = new ConcurrentHashMap<>(); @Value("${bug.image.save.path:F:/GKD/}") private String savePath; private final RestTemplate restTemplate; private final ObjectMapper objectMapper; public BugImageDownloadService(RestTemplate restTemplate, ObjectMapper objectMapper) { this.restTemplate = restTemplate; this.objectMapper = objectMapper; } @PostConstruct public void init() { // 所有设备从固定起始日期开始 LocalDate startDate = LocalDate.of(2025, 7, 1); for (String deviceCode : deviceCodes) { deviceNextDateMap.put(deviceCode, startDate); } System.out.println("[INIT] Device date tracking initialized. Start date: " + startDate); } /** * 持续下载所有设备的新图片 */ public void downloadNewImagesContinuously() { System.out.println("[TASK] ====== CONTINUOUS DOWNLOAD STARTED ======"); System.out.println("[INFO] Devices: " + deviceCodes.size() + " | Save path: " + savePath); while (true) { try { boolean allDevicesUpToDate = true; // 处理每个设备的历史数据 for (String deviceCode : deviceCodes) { LocalDate currentDate = deviceNextDateMap.get(deviceCode); LocalDate today = LocalDate.now(SERVER_ZONE); if (currentDate.isBefore(today)) { allDevicesUpToDate = false; // 处理该设备当前日期的数据 LocalDateTime startOfDay = currentDate.atStartOfDay(); LocalDateTime endOfDay = currentDate.atTime(23, 59, 59); System.out.printf("[PROCESS] Device: %s | Date: %s%n", deviceCode, currentDate); // 下载该日期的图片 int[] counts = downloadImagesForDevice( deviceCode, startOfDay, endOfDay, false // 标记为历史数据请求 ); // 更新设备的下一个处理日期(明天) deviceNextDateMap.put(deviceCode, currentDate.plusDays(1)); System.out.printf("[RESULT] Device: %s | Date: %s | Found: %d | Downloaded: %d | Failed: %d%n", deviceCode, currentDate, counts[0], counts[1], counts[2]); // 设备间处理间隔 Thread.sleep(2000); } } // 所有设备都处理到最新日期 if (allDevicesUpToDate) { System.out.println("[STATUS] All devices up-to-date. Starting real-time updates..."); // ===== 优化后的实更新逻辑 ===== for (String deviceCode : deviceCodes) { // 获取上次更新间(默认当天0点) LocalDateTime lastUpdate = deviceLastUpdateMap.getOrDefault( deviceCode, LocalDate.now(SERVER_ZONE).atStartOfDay() // 使用服务器区 ); LocalDateTime now = LocalDateTime.now(); System.out.printf("[REALTIME] Device: %s | Time range: %s to %s%n", deviceCode, lastUpdate, now); // 修复点1:添加第四个参数 true 表示实请求 int[] counts = downloadImagesForDevice( deviceCode, lastUpdate, // 从上次更新间开始 now, true // 标记为实请求 ); // 更新最后记录间(当前轮询结束间) deviceLastUpdateMap.put(deviceCode, now); System.out.printf("[REALTIME-RESULT] Device: %s | Downloaded: %d | Failed: %d%n", deviceCode, counts[1], counts[2]); // 设备间处理间隔 Thread.sleep(2000); } // ======================== // 等待4h后再次检查 System.out.println("[STATUS] Real-time round completed. Waiting 4 hours..."); Thread.sleep(14_400_000); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); System.err.println("[ERROR] Task interrupted: " + e.getMessage()); break; } catch (Exception e) { System.err.println("[ERROR] Critical error: " + e.getMessage()); try { Thread.sleep(60_000); // 错误后等待1分钟 } catch (InterruptedException ie) { Thread.currentThread().interrupt(); break; } } } } /** * 下载指定设备在指定间范围内的图片 */ private int[] downloadImagesForDevice(String deviceCode, LocalDateTime startTime, LocalDateTime endTime, boolean isRealtime) { int maxRetries = 3; int retryCount = 0; int waitTime = 2000; // 初始等待间 2秒 int total = 0; int success = 0; int failed = 0; while (retryCount < maxRetries) { try { // ====== 网络诊断 ====== // ... [网络诊断代码保持不变] ... // ========== 统一区转换逻辑 ========== ZonedDateTime serverStart = startTime.atZone(ZoneId.systemDefault()) .withZoneSameInstant(SERVER_ZONE); ZonedDateTime serverEnd = endTime.atZone(ZoneId.systemDefault()) .withZoneSameInstant(SERVER_ZONE); // 格式化为API需要的字符串(不进行手动编码) String startStr = serverStart.format(API_DATE_FORMAT); String endStr = serverEnd.format(API_DATE_FORMAT); // 调试日志增强 System.out.println("[DEBUG] Time Parameters:"); System.out.println(" Original Local: " + startTime + " - " + endTime); System.out.println(" Converted Server: " + serverStart.format(API_DATE_FORMAT) + " - " + serverEnd.format(API_DATE_FORMAT)); System.out.println(" Raw Time: " + startStr + " & " + endStr); // 使用Spring的URI构建器确保正确编码 UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(API_URL) .queryParam("deviceCode", deviceCode) .queryParam("startTime", startStr) .queryParam("endTime", endStr) .queryParam("size", 1000) .queryParam("t", System.currentTimeMillis()); URI apiUri = builder.build().encode().toUri(); String apiUrl = apiUri.toString(); System.out.println("[DEBUG] Final request URL: " + apiUrl); // ====== 创建带Cookie的请求头 ====== HttpHeaders headers = new HttpHeaders(); // 添加浏览器级 User-Agent headers.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0"); // 必须添加的请求头 headers.set("Accept", "application/json, text/plain, */*"); headers.set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6"); headers.set("Connection", "keep-alive"); headers.set("Referer", "http://nyzbwlw.com/situation/"); // 关键修复:添加 Referer headers.set("Origin", "http://nyzbwlw.com"); headers.set("Sec-Fetch-Dest", "empty"); headers.set("Sec-Fetch-Mode", "cors"); headers.set("Sec-Fetch-Site", "same-origin"); // 添加 Cookie(关键修复:使用持久化 Cookie) if (!cookies.isEmpty()) { String cookieHeader = cookies.entrySet().stream() .map(entry -> entry.getKey() + "=" + entry.getValue()) .collect(Collectors.joining("; ")); headers.add("Cookie", cookieHeader); System.out.println("[DEBUG] Sending cookies: " + cookieHeader); } // 发送请求 ResponseEntity<String> response = restTemplate.exchange( apiUrl, HttpMethod.GET, new HttpEntity<>(headers), String.class); // 保存新Cookie List<String> setCookieHeaders = response.getHeaders().get("Set-Cookie"); if (setCookieHeaders != null) { for (String cookie : setCookieHeaders) { // 提取关键 Cookie(排除过期/路径信息) String[] cookieParts = cookie.split(";")[0].split("="); if (cookieParts.length >= 2) { String cookieName = cookieParts[0].trim(); String cookieValue = cookieParts[1].trim(); cookies.put(cookieName, cookieValue); System.out.println("[COOKIE] Saved session cookie: " + cookieName); } } } // 响应状态日志 System.out.println("[DEBUG] Response Status: " + response.getStatusCodeValue() + " " + response.getStatusCode().getReasonPhrase()); if (response.getStatusCode().is2xxSuccessful() && response.getBody() != null) { String responseBody = response.getBody(); System.out.println("[DEBUG] Raw API response snippet: " + responseBody.substring(0, Math.min(300, responseBody.length())) + (responseBody.length() > 300 ? "..." : "")); // 使用POJO解析响应 BugApiResponse apiResponse = objectMapper.readValue(responseBody, BugApiResponse.class); System.out.printf("[DEBUG] Parsed API response code: %d | message: %s%n", apiResponse.getCode(), apiResponse.getMsg()); if (apiResponse.getCode() == 100) { BugResponseData data = apiResponse.getData(); List<BugImageInfo> bugList = (data != null && data.getList() != null) ? data.getList() : Collections.emptyList(); total = bugList.size(); System.out.printf("[DEBUG] Found %d valid image entries%n", total); // 如果有数据,处理并返回 if (total > 0) { for (BugImageInfo bug : bugList) { String pictureUrl = bug.getPictureUrl(); String collectionTime = bug.getCollectionTime(); if (pictureUrl != null && !pictureUrl.isEmpty() && collectionTime != null && !collectionTime.isEmpty()) { System.out.printf("[PROCESS] Downloading: %s | %s%n", collectionTime, pictureUrl); if (downloadImage(deviceCode, pictureUrl, collectionTime)) { success++; } else { failed++; } } else { System.err.printf("[WARN] Invalid data: URL=%s | Time=%s%n", pictureUrl, collectionTime); failed++; } } return new int[]{total, success, failed}; } } else { System.err.println("[API-ERROR] Device: " + deviceCode + " | Code: " + apiResponse.getCode()); } } } catch (Exception e) { System.err.println("[DOWNLOAD-ERROR] Device: " + deviceCode + " | Error: " + e.getMessage()); e.printStackTrace(); } // 如果没有数据或出错,等待后重试 retryCount++; if (retryCount < maxRetries) { try { System.out.printf("[RETRY] Retrying in %d ms (attempt %d/%d)%n", waitTime, retryCount + 1, maxRetries); Thread.sleep(waitTime); waitTime *= 2; // 指数退避 } catch (InterruptedException ie) { Thread.currentThread().interrupt(); break; } } } System.out.printf("[STATS] Device: %s | Total: %d | Success: %d | Failed: %d%n", deviceCode, total, success, failed); return new int[]{total, success, failed}; } private boolean downloadImage(String deviceCode, String imageUrl, String collectionTime) { try { LocalDateTime dateTime = LocalDateTime.parse(collectionTime, API_DATE_FORMAT); // 创建保存路径 Path saveDir = Paths.get(savePath, deviceCode, dateTime.format(FILE_DATE_FORMAT)); if (!Files.exists(saveDir)) { Files.createDirectories(saveDir); } // 生成文件名 String fileName = dateTime.format(FILE_TIME_FORMAT) + ".jpg"; Path filePath = saveDir.resolve(fileName); // 跳过已存在文件 if (Files.exists(filePath)) { return true; } // 下载图片 byte[] imageBytes = restTemplate.getForObject(imageUrl, byte[].class); if (imageBytes != null && imageBytes.length > 0) { Files.write(filePath, imageBytes); return true; } } catch (Exception e) { System.err.println("[IMAGE-ERROR] URL: " + imageUrl + " | Error: " + e.getMessage()); } return false; } }解决请求http://nyzbwlw.com/situation/http/device/bug/getBugData?deviceCode=GK2025040006&startTime=2025-07-01%252000:00:00&endTime=2025-07-01%252023:59:59&size=1000&t=1754027017557这个api返回count为0,在浏览器中输入这个url返回13条有效数据{"msg":"操作成功!","code":100,"data":{"count":13,"list":[{"eqName":"GK-7","collectionTime":"2025-07-04 05:28:09","monitorId":250704052841640,"exhibitionPath":"","num":"0","pictureUrl":"https://zzoukeqi.oss-cn-beijing.aliyuncs.com/situations/bugImgs/GK2025040007/2025-07-04/250704052841622749.jpg","pictureAnalysis":{}}
最新发布
08-02
<think>好的,我现在需要解决用户的问题:为什么配置了Nginx的chunked_transfer_encoding on,但响应头里没有Transfer-Encoding: chunked。首先,我得回忆一下Nginx的相关配置和HTTP协议的要求。 用户已经设置了chunked_transfer_encoding on,但响应头没有出现预期的字段。可能的原因有很多,我需要逐步分析。 首先,检查Nginx的配置是否正确。可能用户配置的位置块是否正确应用了?比如是否在正确的location或server块中设置了该指令。还要看是否有其他配置覆盖了这个设置,比如全局的proxy_buffering是否关闭了,因为如果proxy_buffering是开启的,Nginx会缓冲整个响应,这样就不会使用分块传输了。所以用户需要确认proxy_buffering是否确实关闭了。 接下来考虑HTTP协议版本的问题。分块传输编码在HTTP/1.1中支持,但HTTP/1.0不支持。如果客户端使用的是HTTP/1.0,即使服务器配置了,也不会生效。用户可以通过curl -v查看响应使用的协议版本,确认是否是HTTP/1.1。 然后,后端服务器的响应是否有Content-Length头?如果后端已经提供了Content-Length,Nginx可能会优先使用这个,而不启用分块传输。这候需要检查后端应用是否设置了该头,或者Nginx是否有模块自动添加了Content-Length。 另外,检查后端是否本身返回了分块传输。如果后端已经分块,Nginx可能直接透传,而不添加Transfer-Encoding头。这候需要确认后端的行为。 还有可能的是响应体的大小。如果响应体很小,Nginx可能会直接发送完整的Content-Length,而不使用分块。用户可以用大文件测试,看是否出现分块。 此外,某些Nginx模块或配置可能影响分块传输,比如gzip是否开启。如果启用了gzip,可能在压缩过程中缓冲数据,导致分块无法生效。需要确认gzip的设置,或者尝试暂关闭gzip测试。 用户可能需要通过curl -v来查看详细的响应头,或者使用Wireshark抓包分析实际的传输情况,确认是否有分块的特征,比如每个数据块的大小前缀。 总结下来,可能的原因有:配置被覆盖、HTTP版本问题、后端提供Content-Length、响应体太小、模块冲突等。需要逐一排查这些可能性,帮助用户找到问题根源。</think>当Nginx配置了`chunked_transfer_encoding on`但响应头未出现`Transfer-Encoding: chunked`,可能涉及以下多维度的技术原因: --- ### 一、配置冲突检测矩阵 ```mermaid graph TD A[缺失chunked头] --> B[协议版本] A --> C[缓冲机制] A --> D[响应特征] A --> E[后端行为] B --> B1(HTTP/1.0) C --> C1(proxy_buffering未关闭) C --> C2(gzip冲突) D --> D1(Content-Length已存在) D --> D2(空响应体) E --> E1(后端强制Content-Length) ``` --- ### 二、核心排查步骤 #### 1. 协议版本验证 ```bash # 查看实际使用的HTTP协议版本 curl -v 2>&1 | grep -i 'HTTP/' ``` **关键现象**: 若输出`HTTP/1.0 200 OK`,则分块传输自动禁用 **解决方案**: 在配置中强制协议版本: ```nginx proxy_http_version 1.1; ``` --- #### 2. 缓冲配置检查 **冲突检测**: ```nginx # 确认没有冲突配置 location /webapi/user/extractMinutes { proxy_buffering off; # 必须关闭 chunked_transfer_encoding on; # 检查可能覆盖的配置 proxy_max_temp_file_size 0; # 禁用临文件 proxy_request_buffering off; # 关闭请求缓冲 } ``` **缓冲状态验证**: ```bash # 查看实际生效配置 nginx -T | grep -A 10 'location /webapi/user/extractMinutes' ``` --- #### 3. 内容长度冲突 **响应头分析**: ```bash curl -I 2>&1 | grep -iE 'Content-Length|Transfer-Encoding' ``` **故障场景**: 当后端响应包含`Content-Length`头,Nginx优先使用固定长度传输 **强制解决方案**: ```nginx proxy_force_ranges on; # 强制覆盖内容长度 ``` --- ### 三、后端行为诊断 #### 1. 后端响应特征检测 ```bash # 直接请求后端服务验证 curl -v http://127.0.0.1:40330/extractMinutes ``` **关键观察点**: - 后端是否自带`Transfer-Encoding`头 - 后端是否发送`Content-Length`头 --- #### 2. 分块传输强制测试 **生成流式响应**: ```bash # 使用socat模拟分块响应 socat -v tcp-listen:40330,reuseaddr,fork exec:'printf "HTTP/1.1 200 OK\r\n\r\n5\r\nhello\r\n0\r\n\r\n"' ``` **预期结果**: 通过Nginx代理后应看到: ``` Transfer-Encoding: chunked ``` --- ### 四、高级调试技巧 #### 1. 内核级报文分析 ```bash # 使用tcpdump捕获实际报文 sudo tcpdump -i lo -s 0 -A 'tcp port 40330 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' ``` **分块传输特征**: 观察数据包中的`0d 0a`结束符和十六进制块长度前缀 --- #### 2. Nginx调试日志 ```nginx # 启用debug级别日志 error_log /var/log/nginx/debug.log debug; ``` **日志分析重点**: 查找`http filter chunked`相关日志条目 --- ### 五、常见陷阱案例 #### 案例1:gzip压缩冲突 ```nginx # gzip模块会缓冲数据 gzip on; gzip_min_length 0; # 允许压缩小文件 ``` **解决方案**: 禁用压缩或调整阈值: ```nginx gzip off; # 或 gzip_min_length 1024k; # 确保不压缩目标响应 ``` --- #### 案例2:缓存模块干扰 ```nginx proxy_cache_path /tmp/cache keys_zone=mycache:10m; location /webapi/user/extractMinutes { proxy_cache mycache; # 即使proxy_cache off也会影响 } ``` **异常表现**: 缓存逻辑会强制获取完整响应 --- ### 六、配置验证工作流 ```mermaid sequenceDiagram 用户->>Nginx: 发送请求 Nginx->>后端: 代理请求 后端->>Nginx: 流式响应 alt 分块条件满足 Nginx->>客户端: Transfer-Encoding: chunked else Nginx->>客户端: Content-Length end ``` 通过上述多维度排查,可精准定位缺失`Transfer-Encoding: chunked`的根本原因。建议优先检查协议版本、缓冲配置和后端响应特征这三个关键维度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值