简体   繁体   中英

multiple http requests when processing streaming response using httpcomponents

I'm a newbie to http and Apache's HttpComponents API.

I need to process a streaming response of an http request using Apache's HttpComponents, while there may be additional http requests made on that connection. For example, a POST request is initially made to http://mystreams.net , which later follows with additional requests, while throughout I have to listen and process the streaming response. I need to hold the same initial connection I made.

How can I do that? I was able to create a simple HttpClient and do a simple HttpPost request and then process the response entity that is non-streaming, but how do I hold on to it when it continues to stream data and at the same time make new requests to the same address using the same context (ie cookies)?

Is your streaming data coming back as a single HTTP response? If so, you won't be able to receive other responses on that connection until it is done. But you could take the cookies from that response (while it is still streaming the entity to you) and use them to make other requests on another connection.

  • HttpEntity entity = httpclient.execute(httpget).getEntity();
  • InputStream is = entity.getContent()
  • when calling the stream, use a new Thread, and make subsequent requests in the main thread (or, better, in separate thread for reach)

Also check here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM