layout | title | permalink |
---|---|---|
page |
401.09 Reading Notes |
/401-R09/ |
- Local processing
- DNS Request (for IP address)
- TCP Connection (to ensure packet order)
- HTTP Request (request line, header, & body)
- Finish & Acknowledgement packets (both directions)
-
Java uses the
HttpClient
class and contained methods for web requests and responses (formerly usedHttpUrlConnection
class) -
HttpUrlConnection
-
Pros: No library imports required;
-
Cons: Limited functionality compared to other libraries; Many deprecated features;
-
Common request-related methods:
openConnection()
to create instance (of object, not connection itself);.setRequestMethod()
with the argument being the desired request (GET
,DELETE
,TRACE
, etc);getHeaderField()
for reading headers from the calling connection;setConnectTimeout()
(in milliseconds);HttpCookie.parse()
-
-
HttpClient
-
Pros: multiple threads in req/res; easier to maintain; optional asynchronicity;
-
Common request-related methods:
.header()
/.headers()
(depending on if using one pair per or multiple pairs of key-values);timeout()
(with #, then units as args);.newBuilder()
to create a new builder instance which has many related methods;
-