是否有适用于Java的简单http响应解析器? [英] Is there any simple http response parser for Java?

查看:98
本文介绍了是否有适用于Java的简单http响应解析器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何简单的http响应解析器实现?
我的想法是将完整的响应作为一个大字符串输入,并能够通过界面检索状态码,正文等内容。

Is there any simple http response parser implementation? The idea is to put in the complete response as one big string and be able to retrieve stuff like statuscode, body etc. through the interface.

请求/响应不是通过TCP / IP直接发送的,因此除了核心rfc 2616解析实现之外不需要任何其他内容。

The requests/responses are not sent directly over TCP/IP so there is no need for anything but the core rfc 2616 parsing implementation.

推荐答案

如果您使用 Apache HttpClient ,您将获得一个java响应对象,可用于提取标头或邮件正文。请考虑以下示例

If you use for instance Apache HttpClient you will get a java response object which you can use to extract headers or the message body. Consider the following sample

HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(new HttpGet("http://www.foo.com/"));
Header[] headers = response.getAllHeaders();
InputStream responseBody = response.getEntity().getContent();

如果您只想解析响应,可能是 HttpMessageParser 将非常有用:

If you only want to parse a reponse, perhaps the HttpMessageParser will be useful:


抽象消息解析器,用于从任意数据源构建HTTP消息。

Abstract message parser intended to build HTTP messages from an arbitrary data source.

这篇关于是否有适用于Java的简单http响应解析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆