android – How to convert the response from Okhttp into inputstream-ThrowExceptions

Exception or error:


  public static String getRequestNoPayload(String urlString, String loginApi, String mUsername) throws Exception {
        Response response;
            client.setConnectTimeout(20, TimeUnit.SECONDS); // connect timeout
            client.setReadTimeout(20, TimeUnit.SECONDS);    // socket timeout
            Request request = new Request.Builder()

            response = client.newCall(request).execute();

        }catch(Exception e){
            throw e;
        return response.body().string();

What i am trying to do:
I am trying to convert response.body() into a inputstream. How to achieve this

How to solve:

you can get the InputStream through byteStream()


 InputStream is = response.body().byteStream();

to return it you have to change the method’s signature. From String to InputStream

Leave a Reply

Your email address will not be published. Required fields are marked *