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()
转换为inputstream
。如何实现这个
答案 0 :(得分:36)
您可以通过byteStream()
获取InputStreamE.g。
InputStream is = response.body().byteStream();
要返回它,您必须更改方法的签名。从String
到InputStream