提交 562c0871 编写于 作者: R Rossen Stoyanchev

Charset argument in RestClientResponseException

See gh-23803
上级 7f896677
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -99,11 +99,22 @@ public class RestClientResponseException extends RestClientException { ...@@ -99,11 +99,22 @@ public class RestClientResponseException extends RestClientException {
} }
/** /**
* Return the response body as a string. * Return the response body converted to String. The charset used is that
* of the response "Content-Type" or otherwise {@code "UTF-8"}.
*/ */
public String getResponseBodyAsString() { public String getResponseBodyAsString() {
return getResponseBodyAsString(DEFAULT_CHARSET);
}
/**
* Return the response body converted to String. The charset used is that
* of the response "Content-Type" or otherwise the one given.
* @param fallbackCharset the charset to use on if the response doesn't specify.
* @since 5.1.11
*/
public String getResponseBodyAsString(Charset fallbackCharset) {
if (this.responseCharset == null) { if (this.responseCharset == null) {
return new String(this.responseBody, DEFAULT_CHARSET); return new String(this.responseBody, fallbackCharset);
} }
try { try {
return new String(this.responseBody, this.responseCharset); return new String(this.responseBody, this.responseCharset);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册