获取响应获取或发布请求的响应字符集 [英] obtaining response charset of response to get or post request

查看:104
本文介绍了获取响应获取或发布请求的响应字符集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在java web应用程序中提取响应字符集,我正在使用Apache HTTP Client。

I am working to extract response charset in a java web app, where I am using Apache HTTP Client.

例如,从Content-获得一个可能的值输入标题是

For example, one possible value obtained from "Content-Type" header is

    text/html; charset=UTF-8

然后我的代码将在=符号后提取所有文本...

Then my code will extract all text after the "=" sign...

所以提取的字符集将是

    UTF-8

我只是想知道,上述获取响应字符集的方法是否正确?或者是否存在上述代码不起作用的情况?我在这里缺少什么?

I just wanted to know, is the above method for obtaining response charset correct? Or is there some scenario where the above code will not work? Is there something I am missing here?

推荐答案

httpclient(或http核心)是否已提供该功能?这样的事情:

Doesn't httpclient (or http core) already provide that functionality? Something like this:

HttpResponse response = ...
String charset = EntityUtils.getContentCharSet(response.getEntitty());

这篇关于获取响应获取或发布请求的响应字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆