Java连接WebServce
来源:互联网 发布:抗风柱设计软件 编辑:程序博客网 时间:2024/06/06 08:21
package org.external.WeChatBill; import java.io.IOException; import net.sf.json.JSONObject;import org.apache.http.HttpEntity; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse;import org.apache.http.client.methods.HttpPost;import org.apache.http.entity.ContentType;import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients;import org.apache.http.util.EntityUtils; public class postjson { public static String sendInfo(String sendurl, String data) { //System.out.println("data:"+data); CloseableHttpClient client = HttpClients.createDefault(); HttpPost post = new HttpPost(sendurl); StringEntity myEntity = new StringEntity(data, ContentType.APPLICATION_JSON); post.setEntity(myEntity); String responseContent = null; CloseableHttpResponse response = null; try { response = client.execute(post); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); responseContent = EntityUtils.toString(entity, "UTF-8"); String aa = null; } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (response != null) response.close(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (client != null) client.close(); } catch (IOException e) { e.printStackTrace(); } } } return responseContent; }
阅读全文
1 0
- Java连接WebServce
- 直接运行java类来调用webservce接口时发生错误
- Cxf开发webservce实例
- WebServce查询免费的天气预报实例
- JAVA 连接
- Java连接
- 【Java】java连接ldap
- 【Java】Java连接MySql
- java--java连接数据库
- Java 连接SQL Server 连接
- Java连接数据库谈
- java连接sqlserver实例
- java连接sql
- Java开发连接表
- java连接MySql数据库!
- 数据源JAVA连接类
- Java连接数据库
- Java连接数据库谈
- el表达式的转义字符。
- Android常用开发工具类
- @property相关的问题
- Dialog风格的Activity
- robotframework获取数据库返回值“Expression must be a string ,not long”
- Java连接WebServce
- ssh 用法
- Laravel 5.4 官方文档摘记:请求实例
- 机器学习与深度学习(一) 决策树算法 (Decision Tree)
- 动态链接库导出模板类以及一些问题
- 具有P2P及防盗链功能的OTT/IPTV互联网解决方案
- 55 Jump Game
- 将github上的项目整合到jitpack
- 解决Xcode编译错误:does not contain bitcode