SpringbootestClient和RestTemplate记录http请求和响应
在 spring boot(sb) 2 中,配置有所不同,现在在 sb3 中,我们需要以不同的方式配置其余客户端。在 sb3 之前有 resttemplate,现在 spring world 中出现了新的 rest api。在这里查找更多详细信息。
最大的区别是属性配置,它已更改并且未在 spring 站点上记录
logging.level.org.apache.hc.client5.http.wire=debuglogging.level.org.apache.hc.client5.http=debug
仅使用“wire”将提供请求/响应转储。额外的 http=debug 将提供连接和更多调试日志,请在页面末尾找到它。
@beanpublic restclient getwebclient() { return restclient.builder().requestfactory(new httpponentsclienthttprequestfactory()).build();}@beanpublic resttemplate getresttemplate() { resttemplate resttemplate = new resttemplate(); resttemplate.setrequestfactory(new httpponentsclienthttprequestfactory()); return resttemplate;}
控制器端
@getmapping(path = "/hello", produces = "application/json")public string hello() { return client.get().uri("httpbin.org/get?test=2").retrieve().body(string.class);}@getmapping(path = "/hello2", produces = "application/json")public string hello2() { return resttemplate.getforobject("httpbin.org/get?test=1", string.class);}
调试日志
C:Usersozkan.jdksopenjdk-21.0.2injava.exe -XX:TieredStopAtLevel=1 -Dspring.output.ansi.enabled=always -D.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-Dmanagement.endpoints.jmx.exposure.include=*" "-javaagent:C:UsersozkanAppDataLocalProgramsIntelliJ IDEA Ultimatelibidea_rt.jar=49346:C:UsersozkanAppDataLocalProgramsIntelliJ IDEA Ultimatein" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:UsersozkanprojectsHttpDebugLogginguildclassesjavamain;C:UsersozkanprojectsHttpDebugLogginguildesourcesmain;C:Usersozkan.gradlecachesmodules-2iles-2.1org.springframework.bootspring-boot-starter-web.2.5�d75553c6af42122d4db645f4924a95084e382spring-boot-starter-web-3.2.5.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.apache.httpponents.client5httpclient5.3.1.b53c8f4bcdaada801d311cf2ff8a24d6d96883httpclient5-5.3.1.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.springframework.bootspring-boot-starter-json.2.5df311af4c242eb95c3526f48ab4f31c384a247espring-boot-starter-json-3.2.5.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.springframework.bootspring-boot-starter.2.59837a876129cc6fe5f3abf1de5ec0a16faaf003spring-boot-starter-3.2.5.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.springframework.bootspring-boot-starter-tomcat.2.540ebfa6becb35b419b37e49e33b2822e22cf42aspring-boot-starter-tomcat-3.2.5.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.springframeworkspring-webmvc.1.6ef1f76db6d94bac428839cb91fa59235c8356e56spring-webmvc-6.1.6.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.springframeworkspring-web.1.69a32e3497fe39550da3b280bda5d9933ae2d51dspring-web-6.1.6.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.apache.httpponents.core5httpcore5-h2.2.4872764df7b4857549e2880dd32a6f9009166289httpcore5-h2-5.2.4.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.apache.httpponents.core5httpcore5.2.4d8332b975f9e9a8298efe4c883ec43d45b7059httpcore5-5.2.4.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.slf4jslf4j-api.0.1380229737f704b121a318bba5d5deacbcf395bc77slf4j-api-2.0.13.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1.fasterxml.jackson.datatypejackson-datatype-jsr310.15.4de629770a4559db57128d35ccae7d2fddd35db3jackson-datatype-jsr310-2.15.4.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1.fasterxml.jackson.modulejackson-module-parameter-names.15.4e654497a08359db2521b69b5f710e00836915d8cjackson-module-parameter-names-2.15.4.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1.fasterxml.jackson.datatypejackson-datatype-jdk8.15.494777f182334a21bf1aeab1b04cc4398c801f3fjackson-datatype-jdk8-2.15.4.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1.fasterxml.jackson.corejackson-databind.15.4p309fc381f77d4d15c4a4cdaa0db5025c4fd13jackson-databind-2.15.4.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.springframework.bootspring-boot-starter-logging.2.58cf3a346da7bb624381ccc21d7a27500181de63spring-boot-starter-logging-3.2.5.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.springframework.bootspring-boot-autoconfigure.2.5385a2c00a03edb896b2833e4bdee2ae53cd69b8spring-boot-autoconfigure-3.2.5.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.springframework.bootspring-boot.2.5eec72431f6f56a50c9919129665ba3359ca02104spring-boot-3.2.5.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1jakarta.annotationjakarta.annotation-api.1.18b9bda22b091b1f48b13af03fe36db3be6e1ae3jakarta.annotation-api-2.1.1.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.springframeworkspring-core.1.6dea4b8e110b7b54a02a4907e32dbb0adee8a7168spring-core-6.1.6.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.yamlsnakeyaml.2af797a25458550a16bf89acc8e4ab2b7f2bfce0snakeyaml-2.2.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.apache.tomcat.embedomcat-embed-websocket.1.20�02adffaf9e6e4bc2b63a557e348d7f6c0faf7omcat-embed-websocket-10.1.20.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.apache.tomcat.embedomcat-embed-core.1.20a0dc784e12086f83d8e1d5a10443b166abf5780omcat-embed-core-10.1.20.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.apache.tomcat.embedomcat-embed-el.1.20cc1a42b8228699e92c8eba0187eccf54bf892802omcat-embed-el-10.1.20.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.springframeworkspring-context.1.6be30298638975efaf7fff22f1570d79b2679814spring-context-6.1.6.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.springframeworkspring-aop.1.6958f52cb9fcb3adf7e836304550de5431a9347espring-aop-6.1.6.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.springframeworkspring-beans.1.6�d80ff134420db4ebf7614758e6a02a9bd3c41spring-beans-6.1.6.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.springframeworkspring-expression.1.69c3d7f0e17a919a4ea9f087e4e2140ad39776bc8spring-expression-6.1.6.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1io.micrometermicrometer-observation.12.5ee23704259a1aad5c8f503db4d37cdfe5352e766micrometer-observation-1.12.5.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1.fasterxml.jackson.corejackson-annotations.15.4R3ea5a9bf52cdc9c5e537a0e52f2432eaf208bjackson-annotations-2.15.4.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1.fasterxml.jackson.corejackson-core.15.4ebe84b45360debad94f692a4074c6aceb535fa0jackson-core-2.15.4.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1ch.qos.logbacklogback-classic.4.14d98bc162275134cdf1518774da4a2a17ef6fb94dlogback-classic-1.4.14.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.apache.logging.log4jlog4j-to-slf4j.21.1d77b2ba81711ed596cd797cc2b5b5bd7409d841clog4j-to-slf4j-2.21.1.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.slf4jjul-to-slf4j.0.133bcd9d9dd50c71ce69f06b1fd05e40fdeff6ba5jul-to-slf4j-2.0.13.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.springframeworkspring-jcl.1.684cb19b30b22feca73c2ac005ca849c5890935a3spring-jcl-6.1.6.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1io.micrometermicrometer-mons.12.5da45afd81a6a05267df5ddfe10438ea857e0f7d9micrometer-mons-1.12.5.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1ch.qos.logbacklogback-core.4.14d3c2248219ac0effeb380ed4c5280a80bf395e8logback-core-1.4.14.jar;C:Usersozkan.gradlecachesmodules-2iles-2.1org.apache.logging.log4jlog4j-api.21.1<c65e87b9ce1694a01524e192d7be989ba70486log4j-api-2.21.1.jar io.github.ozkanpakdil.cloudtest.CloudTestApplication . _______ _ _ /\ / ___'___ _ _(_)_ ____ _ ( ( )___ | '_ | '_| | '_ / _` | \/ ___)| |_)| | | | | || (_| | ) ) ) ) ' | ____| .__ |_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v3.2.5)INFO io.github.ozkanpakdil.cloudtest.CloudTestApplication – Starting CloudTestApplication using Java 21.0.2 with PID 16624 (C:UsersozkanprojectsHttpDebugLogginguildclassesjavamain started by ozkan in C:UsersozkanprojectsHttpDebugLogging)INFO io.github.ozkanpakdil.cloudtest.CloudTestApplication – No active profile set, falling back to 1 default profile: "default"INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer – Tomcat initialized with port 8080 (http)INFO org.apache.catalina.core.StandardService – Starting service [Tomcat]INFO org.apache.catalina.core.StandardEngine – Starting Servlet engine: [Apache Tomcat/10.1.20]INFO org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/] – Initializing Spring embedded WebApplicationContextINFO org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext – Root WebApplicationContext: initialization pleted in 2800 msINFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer – Tomcat started on port 8080 (http) with context path ''INFO io.github.ozkanpakdil.cloudtest.CloudTestApplication – Started CloudTestApplication in 5.901 seconds (process running for 8.934)INFO org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/] – Initializing Spring DispatcherServlet 'dispatcherServlet'INFO org.springframework.web.servlet.DispatcherServlet – Initializing Servlet 'dispatcherServlet'INFO org.springframework.web.servlet.DispatcherServlet – Completed initialization in 1 msDEBUG org.apache.hc.client5.http.impl.classic.InternalHttpClient – ex-0000000001 preparing request executionDEBUG org.apache.hc.client5.http.impl.classic.ProtocolExec – ex-0000000001 target auth state: UNCHALLENGEDDEBUG org.apache.hc.client5.http.impl.classic.ProtocolExec – ex-0000000001 proxy auth state: UNCHALLENGEDDEBUG org.apache.hc.client5.http.impl.classic.ConnectExec – ex-0000000001 acquiring connection with route {}->httpbin.org:80DEBUG org.apache.hc.client5.http.impl.classic.InternalHttpClient – ex-0000000001 acquiring endpoint (3 MINUTES)DEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ex-0000000001 endpoint lease request (3 MINUTES) [route: {}->httpbin.org:80][total available: 0; route allocated: 0 of 5; total allocated: 0 of 25]DEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ex-0000000001 endpoint leased [route: {}->httpbin.org:80][total available: 0; route allocated: 1 of 5; total allocated: 1 of 25]DEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ex-0000000001 acquired ep-0000000001DEBUG org.apache.hc.client5.http.impl.classic.InternalHttpClient – ex-0000000001 acquired endpoint ep-0000000001DEBUG org.apache.hc.client5.http.impl.classic.ConnectExec – ex-0000000001 opening connection {}->httpbin.org:80DEBUG org.apache.hc.client5.http.impl.classic.InternalHttpClient – ep-0000000001 connecting endpoint (null)DEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ep-0000000001 connecting endpoint to httpbin.org:80 (3 MINUTES)DEBUG org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator – httpbin.org resolving remote addressDEBUG org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator – httpbin.org resolved to [httpbin.org/34.198.16.126, httpbin.org/52.206.26.65, httpbin.org/18.208.239.112, httpbin.org/3.233.6.75]DEBUG org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator – httpbin.org:80 connecting null->httpbin.org/34.198.16.126:80 (3 MINUTES)DEBUG org.apache.hc.client5.http.impl.io.DefaultManagedHttpClientConnection – http-outgoing-0 set socket timeout to 3 MINUTESDEBUG org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator – httpbin.org:80 connected null->httpbin.org/34.198.16.126:80 as http-outgoing-0DEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ep-0000000001 connected http-outgoing-0DEBUG org.apache.hc.client5.http.impl.classic.InternalHttpClient – ep-0000000001 endpoint connectedDEBUG org.apache.hc.client5.http.impl.classic.MainClientExec – ex-0000000001 executing GET /get?test=2 HTTP/1.1DEBUG org.apache.hc.client5.http.protocol.RequestAddCookies – ex-0000000001 Cookie spec selected: strictDEBUG org.apache.hc.client5.http.impl.classic.InternalHttpClient – ep-0000000001 start execution ex-0000000001DEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ep-0000000001 executing exchange ex-0000000001 over http-outgoing-0DEBUG org.apache.hc.client5.http.headers – http-outgoing-0 GET /get?test=2 HTTP/1.1DEBUG org.apache.hc.client5.http.headers – http-outgoing-0 Accept-Encoding: gzip, x-gzip, deflateDEBUG org.apache.hc.client5.http.headers – http-outgoing-0 Host: httpbin.orgDEBUG org.apache.hc.client5.http.headers – http-outgoing-0 Connection: keep-aliveDEBUG org.apache.hc.client5.http.headers – http-outgoing-0 User-Agent: Apache-HttpClient/5.3.1 (Java/21.0.2)DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 "GET /get?test=2 HTTP/1.1[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 "Accept-Encoding: gzip, x-gzip, deflate[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 "Host: httpbin.org[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 "Connection: keep-alive[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 "User-Agent: Apache-HttpClient/5.3.1 (Java/21.0.2)[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 "[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << "HTTP/1.1 200 OK[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << "Date: Sat, 18 May 2024 19:01:33 GMT[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << "Content-Type: application/json[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << "Content-Length: 332[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << "Connection: keep-alive[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << "Server: gunicorn/19.9.0[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << "Access-Control-Allow-Origin: *[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << "Access-Control-Allow-Credentials: true[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << "[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << "{[]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << " "args": {[]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << " "test": "2"[]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << " }, []"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << " "headers": {[]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << " "Accept-Encoding": "gzip, x-gzip, deflate", []"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << " "Host": "httpbin.org", []"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << " "User-Agent": "Apache-HttpClient/5.3.1 (Java/21.0.2)", []"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << " "X-Amzn-Trace-Id": "Root=1-6648fb0d-38aeda533a97acd53fdb1f56"[]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << " }, []"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << " "origin": "82.12.84.124", []"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << " "url": "httpbin.org/get?test=2"[]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-0 << "}[]"DEBUG org.apache.hc.client5.http.headers – http-outgoing-0 << HTTP/1.1 200 OKDEBUG org.apache.hc.client5.http.headers – http-outgoing-0 << Date: Sat, 18 May 2024 19:01:33 GMTDEBUG org.apache.hc.client5.http.headers – http-outgoing-0 << Content-Type: application/jsonDEBUG org.apache.hc.client5.http.headers – http-outgoing-0 << Content-Length: 332DEBUG org.apache.hc.client5.http.headers – http-outgoing-0 << Connection: keep-aliveDEBUG org.apache.hc.client5.http.headers – http-outgoing-0 << Server: gunicorn/19.9.0DEBUG org.apache.hc.client5.http.headers – http-outgoing-0 << Access-Control-Allow-Origin: *DEBUG org.apache.hc.client5.http.headers – http-outgoing-0 << Access-Control-Allow-Credentials: trueDEBUG org.apache.hc.client5.http.impl.classic.MainClientExec – ex-0000000001 connection can be kept alive for 3 MINUTESDEBUG org.apache.hc.client5.http.impl.classic.InternalHttpClient – ep-0000000001 releasing valid endpointDEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ep-0000000001 releasing endpointDEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ep-0000000001 connection http-outgoing-0 can be kept alive for 3 MINUTESDEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ep-0000000001 connection released [route: {}->httpbin.org:80][total available: 1; route allocated: 1 of 5; total allocated: 1 of 25]DEBUG org.apache.hc.client5.http.impl.classic.InternalHttpClient – ex-0000000002 preparing request executionDEBUG org.apache.hc.client5.http.impl.classic.ProtocolExec – ex-0000000002 target auth state: UNCHALLENGEDDEBUG org.apache.hc.client5.http.impl.classic.ProtocolExec – ex-0000000002 proxy auth state: UNCHALLENGEDDEBUG org.apache.hc.client5.http.impl.classic.ConnectExec – ex-0000000002 acquiring connection with route {}->httpbin.org:80DEBUG org.apache.hc.client5.http.impl.classic.InternalHttpClient – ex-0000000002 acquiring endpoint (3 MINUTES)DEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ex-0000000002 endpoint lease request (3 MINUTES) [route: {}->httpbin.org:80][total available: 0; route allocated: 0 of 5; total allocated: 0 of 25]DEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ex-0000000002 endpoint leased [route: {}->httpbin.org:80][total available: 0; route allocated: 1 of 5; total allocated: 1 of 25]DEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ex-0000000002 acquired ep-0000000002DEBUG org.apache.hc.client5.http.impl.classic.InternalHttpClient – ex-0000000002 acquired endpoint ep-0000000002DEBUG org.apache.hc.client5.http.impl.classic.ConnectExec – ex-0000000002 opening connection {}->httpbin.org:80DEBUG org.apache.hc.client5.http.impl.classic.InternalHttpClient – ep-0000000002 connecting endpoint (null)DEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ep-0000000002 connecting endpoint to httpbin.org:80 (3 MINUTES)DEBUG org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator – httpbin.org resolving remote addressDEBUG org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator – httpbin.org resolved to [httpbin.org/34.198.16.126, httpbin.org/52.206.26.65, httpbin.org/18.208.239.112, httpbin.org/3.233.6.75]DEBUG org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator – httpbin.org:80 connecting null->httpbin.org/34.198.16.126:80 (3 MINUTES)DEBUG org.apache.hc.client5.http.impl.io.DefaultManagedHttpClientConnection – http-outgoing-1 set socket timeout to 3 MINUTESDEBUG org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator – httpbin.org:80 connected null->httpbin.org/34.198.16.126:80 as http-outgoing-1DEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ep-0000000002 connected http-outgoing-1DEBUG org.apache.hc.client5.http.impl.classic.InternalHttpClient – ep-0000000002 endpoint connectedDEBUG org.apache.hc.client5.http.impl.classic.MainClientExec – ex-0000000002 executing GET /get?test=1 HTTP/1.1DEBUG org.apache.hc.client5.http.protocol.RequestAddCookies – ex-0000000002 Cookie spec selected: strictDEBUG org.apache.hc.client5.http.impl.classic.InternalHttpClient – ep-0000000002 start execution ex-0000000002DEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ep-0000000002 executing exchange ex-0000000002 over http-outgoing-1DEBUG org.apache.hc.client5.http.headers – http-outgoing-1 GET /get?test=1 HTTP/1.1DEBUG org.apache.hc.client5.http.headers – http-outgoing-1 Accept: text/plain, application/json, application/*+json, */*DEBUG org.apache.hc.client5.http.headers – http-outgoing-1 Accept-Encoding: gzip, x-gzip, deflateDEBUG org.apache.hc.client5.http.headers – http-outgoing-1 Host: httpbin.orgDEBUG org.apache.hc.client5.http.headers – http-outgoing-1 Connection: keep-aliveDEBUG org.apache.hc.client5.http.headers – http-outgoing-1 User-Agent: Apache-HttpClient/5.3.1 (Java/21.0.2)DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 "GET /get?test=1 HTTP/1.1[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 "Accept: text/plain, application/json, application/*+json, */*[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 "Accept-Encoding: gzip, x-gzip, deflate[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 "Host: httpbin.org[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 "Connection: keep-alive[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 "User-Agent: Apache-HttpClient/5.3.1 (Java/21.0.2)[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 "[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << "HTTP/1.1 200 OK[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << "Date: Sat, 18 May 2024 19:01:37 GMT[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << "Content-Type: application/json[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << "Content-Length: 404[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << "Connection: keep-alive[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << "Server: gunicorn/19.9.0[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << "Access-Control-Allow-Origin: *[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << "Access-Control-Allow-Credentials: true[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << "[][]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << "{[]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << " "args": {[]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << " "test": "1"[]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << " }, []"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << " "headers": {[]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << " "Accept": "text/plain, application/json, application/*+json, */*", []"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << " "Accept-Encoding": "gzip, x-gzip, deflate", []"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << " "Host": "httpbin.org", []"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << " "User-Agent": "Apache-HttpClient/5.3.1 (Java/21.0.2)", []"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << " "X-Amzn-Trace-Id": "Root=1-6648fb11-4bc979503c1426712721796a"[]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << " }, []"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << " "origin": "82.12.84.124", []"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << " "url": "httpbin.org/get?test=1"[]"DEBUG org.apache.hc.client5.http.wire – http-outgoing-1 << "}[]"DEBUG org.apache.hc.client5.http.headers – http-outgoing-1 << HTTP/1.1 200 OKDEBUG org.apache.hc.client5.http.headers – http-outgoing-1 << Date: Sat, 18 May 2024 19:01:37 GMTDEBUG org.apache.hc.client5.http.headers – http-outgoing-1 << Content-Type: application/jsonDEBUG org.apache.hc.client5.http.headers – http-outgoing-1 << Content-Length: 404DEBUG org.apache.hc.client5.http.headers – http-outgoing-1 << Connection: keep-aliveDEBUG org.apache.hc.client5.http.headers – http-outgoing-1 << Server: gunicorn/19.9.0DEBUG org.apache.hc.client5.http.headers – http-outgoing-1 << Access-Control-Allow-Origin: *DEBUG org.apache.hc.client5.http.headers – http-outgoing-1 << Access-Control-Allow-Credentials: trueDEBUG org.apache.hc.client5.http.impl.classic.MainClientExec – ex-0000000002 connection can be kept alive for 3 MINUTESDEBUG org.apache.hc.client5.http.impl.classic.InternalHttpClient – ep-0000000002 releasing valid endpointDEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ep-0000000002 releasing endpointDEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ep-0000000002 connection http-outgoing-1 can be kept alive for 3 MINUTESDEBUG org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager – ep-0000000002 connection released [route: {}->httpbin.org:80][total available: 1; route allocated: 1 of 5; total allocated: 1 of 25]
在这里找到完整的工作示例
以上就是Spring boot estClient 和 RestTemplate 记录 http 请求和响应的详细内容,更多请关注范的资源库其它相关文章!