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.
The requests/responses are not sent directly over TCP/IP so there is no need for anything but the core rfc 2616 parsing implementation.
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();
If you only want to parse a reponse, perhaps the HttpMessageParser
will be useful:
Abstract message parser intended to build HTTP messages from an arbitrary data source.
I recomend http-request built on apache http api.
HttpRequest<String> httpRequest = HttpRequestBuilder.createGet(someUri, String.class)
.responseDeserializer(ResponseDeserializer.ignorableDeserializer())
.build();
public void send(){
ResponseHandler<String> responseHandler = httpRequest.execute();
String responseBody = responseHandler.get();
int statusCode = responseHandler.getStatusCode();
}
I higly recomend read documentation before use.