|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2017 the original author or authors. |
| 2 | + * Copyright 2002-2019 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -33,7 +33,7 @@ public class RestClientResponseException extends RestClientException {
|
33 | 33 |
|
34 | 34 | private static final long serialVersionUID = -8803556342728481792L;
|
35 | 35 |
|
36 |
| - private static final Charset DEFAULT_CHARSET = StandardCharsets.ISO_8859_1; |
| 36 | + private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; |
37 | 37 |
|
38 | 38 |
|
39 | 39 | private final int rawStatusCode;
|
@@ -99,11 +99,22 @@ public byte[] getResponseBodyAsByteArray() {
|
99 | 99 | }
|
100 | 100 |
|
101 | 101 | /**
|
102 |
| - * Return the response body as a string. |
| 102 | + * Return the response body converted to String. The charset used is that |
| 103 | + * of the response "Content-Type" or otherwise {@code "UTF-8"}. |
103 | 104 | */
|
104 | 105 | public String getResponseBodyAsString() {
|
| 106 | + return getResponseBodyAsString(DEFAULT_CHARSET); |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Return the response body converted to String. The charset used is that |
| 111 | + * of the response "Content-Type" or otherwise the one given. |
| 112 | + * @param fallbackCharset the charset to use on if the response doesn't specify. |
| 113 | + * @since 5.1.11 |
| 114 | + */ |
| 115 | + public String getResponseBodyAsString(Charset fallbackCharset) { |
105 | 116 | if (this.responseCharset == null) {
|
106 |
| - return new String(this.responseBody, DEFAULT_CHARSET); |
| 117 | + return new String(this.responseBody, fallbackCharset); |
107 | 118 | }
|
108 | 119 | try {
|
109 | 120 | return new String(this.responseBody, this.responseCharset);
|
|
0 commit comments