This commit is contained in:
Redkale
2019-05-28 17:43:48 +08:00
parent 6a8c86096b
commit ca1f974dbe

View File

@@ -1980,14 +1980,14 @@ public final class Utility {
}
conn.setRequestMethod(method);
if (headers != null) {
for (Map.Entry<String, String> en : headers.entrySet()) { //不用forEach是为了兼容JDK 6
for (Map.Entry<String, String> en : headers.entrySet()) {
conn.setRequestProperty(en.getKey(), en.getValue());
}
}
if (body != null && !body.isEmpty()) { //conn.getOutputStream()会将GET强制变成POST
conn.setDoInput(true);
conn.setDoOutput(true);
conn.getOutputStream().write(body == null ? new byte[0] : body.getBytes(UTF_8));
conn.getOutputStream().write(body.getBytes(UTF_8));
}
conn.connect();
int rs = conn.getResponseCode();