知乎專欄 | 多維度架構 | | | 微信號 netkiller-ebook | | | QQ群:128659835 請註明“讀者” |
OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("http://www.netkiller.cn") .build(); Response response = client.newCall(request).execute(); if (!response.isSuccessful()) { throw new IOException("伺服器端錯誤: " + response); } Headers responseHeaders = response.headers(); for (int i = 0; i < responseHeaders.size(); i++) { System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i)); } System.out.println(response.body().string());