Java: Display request of an HttpURLConnection before sending

前端 未结 3 2059
小鲜肉
小鲜肉 2020-12-15 18:30

I want to make some API calls to a server using HttpURLConnection. But the requests are not successful, returning:


  

        
相关标签:
3条回答
  • 2020-12-15 19:11

    Use something like tcpdump, which can dump the actual network packets that are emitted or received by your computer.

    0 讨论(0)
  • 2020-12-15 19:26

    You can put the HttpURLConnection in debug mode by enabling java.logging with

    -Djava.util.logging.config.file=logging.properties
    

    and put in logging.properties (by default in JRE_HOME\lib) the following property

    sun.net.www.protocol.http.HttpURLConnection.level = ALL
    
    0 讨论(0)
  • 2020-12-15 19:30

    tcpdump will work, but it can be hard to make it do what you want. NetCat is more user-friendly (here's the project page: http://netcat.sourceforge.net/ - most Unix platforms already include it).

    nc -l 9999
    

    This will listen on TCP port 9999, and when an HTTP client connects, it'll print out the full text of the request.

    0 讨论(0)
提交回复
热议问题