本文整理了Java中jodd.http.HttpResponse.charset()
方法的一些代码示例,展示了HttpResponse.charset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.charset()
方法的具体详情如下:
包路径:jodd.http.HttpResponse
类名称:HttpResponse
方法名:charset
暂无
代码示例来源:origin: oblac/jodd
assertEquals("text/html;charset=UTF-8" , response.contentType());
assertEquals("text/html" , response.mediaType());
assertEquals("UTF-8" , response.charset());
代码示例来源:origin: com.github.binarywang/weixin-java-pay
private String getResponseString(HttpResponse response) throws WxPayException {
try {
this.log.debug("【微信服务器响应头信息】:\n{}", response.toString(false));
} catch (NullPointerException e) {
this.log.warn("HttpResponse.toString() 居然抛出空指针异常了", e);
}
String responseString = response.bodyText();
if (StringUtils.isBlank(responseString)) {
throw new WxPayException("响应信息为空");
}
if (StringUtils.isBlank(response.charset())) {
responseString = new String(responseString.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
}
return responseString;
}
代码示例来源:origin: binarywang/WxJava
private String getResponseString(HttpResponse response) throws WxPayException {
try {
this.log.debug("【微信服务器响应头信息】:\n{}", response.toString(false));
} catch (NullPointerException e) {
this.log.warn("HttpResponse.toString() 居然抛出空指针异常了", e);
}
String responseString = response.bodyText();
if (StringUtils.isBlank(responseString)) {
throw new WxPayException("响应信息为空");
}
if (StringUtils.isBlank(response.charset())) {
responseString = new String(responseString.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
}
return responseString;
}
代码示例来源:origin: com.gitee.morilys.jsmile/jsmile-kit
/**
* http get请求
* @param url 请求地址
* @param param 请求参数
* @return
*/
public static String post(String url, Map<String,Object> param,Map<String,String> headers){
String result=null;
try {
HttpRequest httpRequest = HttpRequest.post(url);
if(null!=param){
httpRequest.form(param);
}
if(headers!=null&&!headers.isEmpty()){
httpRequest.header(headers);
}
HttpResponse response = httpRequest.send().charset(HttpConstant.Charsets.DEFAULT_CHARSET);
result = response.bodyText();
}catch (Exception e){
logger.error("HTTP请求地址【" + url + "】发生异常:" + ExceptionUtils.getRootCause(e));
}
return result;
}
代码示例来源:origin: com.gitee.morilys.jsmile/jsmile-kit
/**
* http get请求
* @param url 请求地址
* @param param 请求参数
* @return
*/
public static String get(String url, Map<String,String> param,Map<String,String> headers){
String result=null;
try {
HttpRequest httpRequest = HttpRequest.get(url);
if(null!=param){
httpRequest.query(param);
}
if(headers!=null&&!headers.isEmpty()){
httpRequest.header(headers);
}
HttpResponse response = httpRequest.send().charset(HttpConstant.Charsets.DEFAULT_CHARSET);
result = response.bodyText();
}catch (Exception e){
logger.error("HTTP请求地址【" + url + "】发生异常:" + ExceptionUtils.getRootCause(e));
}
return result;
}
public static String get(String url, Map<String,String> param){
代码示例来源:origin: com.gitee.morilys.jsmile/jsmile-kit
/**
* http post请求(body带参)
* @param url 请求地址
* @param param 请求参数
* @return
*/
public static String body(String url, Map<String,Object> param,Map<String,String> headers){
String result=null;
try {
HttpRequest httpRequest = HttpRequest.post(url).contentTypeJson();
if(null!=param){
httpRequest.body(JSON.toJSONString(param));
}else{
httpRequest.body("{}");
}
if(headers!=null&&!headers.isEmpty()){
httpRequest.header(headers);
}
HttpResponse response = httpRequest.send().charset(HttpConstant.Charsets.DEFAULT_CHARSET);
result = response.bodyText();
}catch (Exception e){
logger.error("HTTP请求地址【" + url + "】发生异常:" + ExceptionUtils.getRootCause(e));
}
return result;
}
代码示例来源:origin: com.github.binarywang/weixin-java-common
response.charset(StringPool.UTF_8);
代码示例来源:origin: com.github.binarywang/weixin-java-mp
@Override
public WxMpMaterialNews execute(String uri, String materialId) throws WxErrorException, IOException {
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
HttpRequest request = HttpRequest.post(uri)
.withConnectionProvider(requestHttp.getRequestHttpClient())
.body(WxGsonBuilder.create().toJson(ImmutableMap.of("media_id", materialId)));
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
this.logger.debug("响应原始数据:{}", responseContent);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {
return WxMpGsonBuilder.create().fromJson(responseContent, WxMpMaterialNews.class);
}
}
}
代码示例来源:origin: binarywang/WxJava
@Override
public WxMpMaterialNews execute(String uri, String materialId) throws WxErrorException, IOException {
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
HttpRequest request = HttpRequest.post(uri)
.withConnectionProvider(requestHttp.getRequestHttpClient())
.body(WxGsonBuilder.create().toJson(ImmutableMap.of("media_id", materialId)));
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
this.logger.debug("响应原始数据:{}", responseContent);
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {
return WxMpGsonBuilder.create().fromJson(responseContent, WxMpMaterialNews.class);
}
}
}
代码示例来源:origin: binarywang/WxJava
@Override
public String execute(String uri, String queryParam) throws WxErrorException, IOException {
if (queryParam != null) {
if (uri.indexOf('?') == -1) {
uri += '?';
}
uri += uri.endsWith("?") ? queryParam : '&' + queryParam;
}
HttpRequest request = HttpRequest.get(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return responseContent;
}
代码示例来源:origin: com.github.binarywang/weixin-java-common
@Override
public String execute(String uri, String queryParam) throws WxErrorException, IOException {
if (queryParam != null) {
if (uri.indexOf('?') == -1) {
uri += '?';
}
uri += uri.endsWith("?") ? queryParam : '&' + queryParam;
}
HttpRequest request = HttpRequest.get(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return responseContent;
}
代码示例来源:origin: com.github.binarywang/weixin-java-mp
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent, WxType.MP);
代码示例来源:origin: binarywang/WxJava
@Override
public Boolean execute(String uri, String materialId) throws WxErrorException, IOException {
HttpRequest request = HttpRequest.post(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
request.query("media_id", materialId);
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {
return true;
}
}
}
代码示例来源:origin: com.github.binarywang/weixin-java-mp
@Override
public Boolean execute(String uri, String materialId) throws WxErrorException, IOException {
HttpRequest request = HttpRequest.post(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
request.query("media_id", materialId);
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {
return true;
}
}
}
代码示例来源:origin: com.github.binarywang/weixin-java-mp
@Override
public WxMpMaterialVideoInfoResult execute(String uri, String materialId) throws WxErrorException, IOException {
HttpRequest request = HttpRequest.post(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
request.query("media_id", materialId);
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {
return WxMpMaterialVideoInfoResult.fromJson(responseContent);
}
}
}
代码示例来源:origin: com.github.binarywang/weixin-java-common
@Override
public WxMediaUploadResult execute(String uri, File file) throws WxErrorException, IOException {
HttpRequest request = HttpRequest.post(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
request.form("media", file);
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return WxMediaUploadResult.fromJson(responseContent);
}
}
代码示例来源:origin: binarywang/WxJava
@Override
public WxMediaUploadResult execute(String uri, File file) throws WxErrorException, IOException {
HttpRequest request = HttpRequest.post(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
request.form("media", file);
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return WxMediaUploadResult.fromJson(responseContent);
}
}
代码示例来源:origin: binarywang/WxJava
@Override
public WxMpMaterialVideoInfoResult execute(String uri, String materialId) throws WxErrorException, IOException {
HttpRequest request = HttpRequest.post(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
request.query("media_id", materialId);
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
} else {
return WxMpMaterialVideoInfoResult.fromJson(responseContent);
}
}
}
代码示例来源:origin: com.github.binarywang/weixin-java-mp
@Override
public WxMediaImgUploadResult execute(String uri, File data) throws WxErrorException, IOException {
if (data == null) {
throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("文件对象为空").build());
}
HttpRequest request = HttpRequest.post(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
request.form("media", data);
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return WxMediaImgUploadResult.fromJson(responseContent);
}
}
代码示例来源:origin: binarywang/WxJava
@Override
public WxMediaImgUploadResult execute(String uri, File data) throws WxErrorException, IOException {
if (data == null) {
throw new WxErrorException(WxError.builder().errorCode(-1).errorMsg("文件对象为空").build());
}
HttpRequest request = HttpRequest.post(uri);
if (requestHttp.getRequestHttpProxy() != null) {
requestHttp.getRequestHttpClient().useProxy(requestHttp.getRequestHttpProxy());
}
request.withConnectionProvider(requestHttp.getRequestHttpClient());
request.form("media", data);
HttpResponse response = request.send();
response.charset(StringPool.UTF_8);
String responseContent = response.bodyText();
WxError error = WxError.fromJson(responseContent, WxType.MP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return WxMediaImgUploadResult.fromJson(responseContent);
}
}
内容来源于网络,如有侵权,请联系作者删除!