How do I make a raw HTTP request in Java?

2019-03-01 12:09发布

问题:

I want to make a basic HTTP request using these tokens: http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html

I know Java does it for you normally, but I want to specifically set certain tokens.

回答1:

Why reinvent the wheel ? The Apache Http Client 4 conforms to rfc2616.



回答2:

Open a socket to port 80 on the host you want to connect to, and then just write to the stream in the same way you'd write to a file or the console.



标签: java http