码:
public static String getRequestNoPayload(String urlString,String loginApi,String mUsername) throws Exception { Response response; try{ client.setConnectTimeout(20,TimeUnit.SECONDS); // connect timeout client.setReadTimeout(20,TimeUnit.SECONDS); // socket timeout Request request = new Request.Builder() .url(urlString) .addHeader("username",loginApi) .addHeader("password",mUsername) .build(); response = client.newCall(request).execute(); }catch(Exception e){ throw e; } return response.body().string(); }
我正在努力做什么:
我正在尝试将response.body()转换为输入流.如何实现这一点
解决方法
您可以通过
byteStream()获取InputStream
例如.
InputStream is = response.body().byteStream();
要返回它,你必须更改方法的签名.从String到InputStream