如何从HttpURLConnection读取完整的响应?
2022-09-02 00:59:16
我在andorid中制作了一些代理服务器,这些服务器修改了http标头,它工作正常,但我必须将完整响应转发到“顶层”。
如何从 HttpURLConnection 读取整个响应(所有标头、内容、所有内容)?
HttpURLConnection httpURLConnection;
URL url = new URL(ADDRESS);
httpURLConnection = (HttpURLConnection) url.openConnection();
// add headers, write output stream, flush
if (httpURLConnection.getResponseCode() == HttpsURLConnection.HTTP_OK)
{
Map<String, List<String>> map = httpURLConnection.getHeaderFields();
System.out.println("Printing Response Header...\n");
for (Map.Entry<String, List<String>> entry : map.entrySet())
{
System.out.println("Key : " + entry.getKey() + " ,Value : " + entry.getValue());
}
return new DataInputStream(httpURLConnection.getInputStream());
}
在getInputStream中,我只收到内容,是否有可能有一些带有整个存储库的流?