I have an android application and I am trying to make an http/2 call with okHttp version 3.13.1, in my case for one request I will be receiving two responses sequentially from the server, but with the okHttp client I am getting only one response and if I try to send the request using curl command I am receiving two responses sequentially from the server.
Is there a way to handle multiple responses for a single http/2 request in android?
I tried various ways, but no luck:( Would be more than happy, if anyone could provide your inputs.
Thanks for your help and time in advance!!!
I am basically sending a get request from my android application using okHttp client to a server which supports http/2, so expecting to receive 2 different response for that single request in a timely manner.i.e the second response will be sent from the server after 5 seconds gap of receiving the first response.
Below is my response :
But, in my case once I receive the first response the client is no longer listing to the server. When I receive the first response, in my log I see :
com.example.okhttp3 D/OkHttp: <– END HTTP (166-byte body),
so not receiving the second response.
Appreciate your help!
I found a workaround. You can send the response as multipart data. Then encapsulate all your responses into the multipart data seperated by ‘boundary’. The multipart data will not end until you send the ‘end mark'(0). Then the client side could decode all the responses one by one simultaneously when the server sending the multipart data.
The multipart data will looks like this:
--boundary response_1 --boundary response_2 ... --boundary-- 0
there is also a demo here.