服务器根据URL以及data信息与微信服务器交互的post请求方法(之一)
来源:互联网 发布:淘宝购物怎样返利 编辑:程序博客网 时间:2024/06/08 04:12
/**
* POST请求
*
* @param url
* URL
* @param xml
* XML
* @return 返回结果
*/
public static String post(String url, String xml) {
Assert.hasText(url);
String result = null;
try {
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(xml, "UTF-8"));
CloseableHttpResponse httpResponse = HTTP_CLIENT.execute(httpPost);
try {
HttpEntity httpEntity = httpResponse.getEntity();
if (httpEntity != null) {
result = EntityUtils.toString(httpEntity, "UTF-8");
EntityUtils.consume(httpEntity);
}
} finally {
try {
httpResponse.close();
} catch (IOException e) {
}
}
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (ClientProtocolException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (ParseException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
return result;
* POST请求
*
* @param url
* URL
* @param xml
* XML
* @return 返回结果
*/
public static String post(String url, String xml) {
Assert.hasText(url);
String result = null;
try {
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(xml, "UTF-8"));
CloseableHttpResponse httpResponse = HTTP_CLIENT.execute(httpPost);
try {
HttpEntity httpEntity = httpResponse.getEntity();
if (httpEntity != null) {
result = EntityUtils.toString(httpEntity, "UTF-8");
EntityUtils.consume(httpEntity);
}
} finally {
try {
httpResponse.close();
} catch (IOException e) {
}
}
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (ClientProtocolException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (ParseException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
return result;
}
某作者的Java微信公众平台开发之生成带参二维码 可以去参考
阅读全文
0 0
- 服务器根据URL以及data信息与微信服务器交互的post请求方法(之一)
- HTTP请求的方法(与服务器交互方法)
- Http与服务器的交互(主要post和get)
- Http服务器的交互请求 GET,POST,PUT和DELETE
- 向指定服务器URL 发送POST方法的请求并用JSON表示
- (基于nodejs)微信测试号(接口配置信息)验证服务器的URL
- java的URL类使用和模拟POST请求服务器
- 向指定 URL 发送GET,POST方法的请求(传入指定url和参数,服务器返回字符串数据)
- Java获取此次请求URL以及服务器根路径的方法
- Java获取此次请求URL以及服务器根路径的方法
- Java获取此次请求URL以及服务器根路径的方法
- Get和Post与服务器交互的区别
- Get和Post与服务器交互的区别
- web服务器的post请求
- Flex与服务器交互之一(URLRequest +URLLoader应用)
- Flex与服务器交互之一(URLRequest +URLLoader应用)
- Flex与服务器交互之一(URLRequest +URLLoader应用)
- IOS 请求服务器的两种方法GET 和 POST
- JavaWeb笔记之数据源连接池
- NASA无人机障碍赛:专业选手Vs.人工智能,赌一赌谁赢?
- URL 规范
- hibernate学习教程-数据缓存
- C++ 显示数据库的数据到界面
- 服务器根据URL以及data信息与微信服务器交互的post请求方法(之一)
- python2的编码问题
- Iptables教程
- XMLHttpRequest
- 最小生成树--Truck History(poj 1789);
- 云星数据---Scala实战系列(精品版)】:Scala入门教程014-Scala实战源码-Scala函数定义与调用方式
- [图]Microsoft Store上线字体:未来Windows 10可轻松切换字体
- CSS样式添加及基础语法------借鉴w3shool.com.cn
- java.util.ArrayList与java.util.Arrays$ArrayList区别(转)