插件开发工具库,推荐依赖该工具库。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

39 lines
1015 B

package com.fanruan.api.net.http.rs;
import com.fr.third.org.apache.http.HttpEntity;
import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse;
import com.fr.third.org.apache.http.util.EntityUtils;
import java.io.IOException;
/**
* 文本响应解析器
*
* @author vito
* @since 2019-07-14
*/
public class TextResponseHandle extends BaseHttpResponseHandle<String> {
public static final TextResponseHandle DEFAULT = new TextResponseHandle();
public TextResponseHandle() {
}
public TextResponseHandle(String encoding) {
super(encoding);
}
@Override
public String parse(CloseableHttpResponse response) throws IOException {
try {
HttpEntity entity = response.getEntity();
String result = EntityUtils.toString(entity, getEncoding());
EntityUtils.consume(entity);
return result;
} finally {
if (response != null) {
response.close();
}
}
}
}