Skip to content

Latest commit

 

History

History
33 lines (21 loc) · 1.29 KB

401-09.md

File metadata and controls

33 lines (21 loc) · 1.29 KB
layout title permalink
page
401.09 Reading Notes
/401-R09/

Java's Web Request Response Cycle

WRRC Overview

  1. Local processing
  2. DNS Request (for IP address)
  3. TCP Connection (to ensure packet order)
  4. HTTP Request (request line, header, & body)
  5. Finish & Acknowledgement packets (both directions)

Java's WRRC

  • Java uses the HttpClient class and contained methods for web requests and responses (formerly used HttpUrlConnection 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;