Read from InputStream in multiple formats

前端 未结 3 1356
情话喂你
情话喂你 2021-01-12 18:31

I\'m trying to write a class that reads HTTP requests and responses and parses them. Since the headers are ordinary text it seemed easiest to read them using a Buffe

3条回答
  •  被撕碎了的回忆
    2021-01-12 19:10

    There is already a class in Java for handling HTTP requests and responses. You should use that instead of trying to parse the response on your own. Parsing HTTP response is more difficult than you think as there are different encoding methods that you have to deal with. It isn't really raw binary data in the response payload. The HttpURLConnection class will parse headers for you and give you InputStream for the payload.

    http://download.oracle.com/javase/1.4.2/docs/api/java/net/HttpURLConnection.html

提交回复
热议问题