java代码发送HTTP Post请求
来源:互联网 发布:常用的外文数据库 编辑:程序博客网 时间:2024/05/23 01:44
代码如下,不用过多解释了吧:
package imscportal.transform.http.channel.impl;import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.OutputStream;import java.net.HttpURLConnection;import java.net.URL;import java.net.URLDecoder;import imscportal.transform.http.channel.spi.IHttpChannel;import imscportal.util.log.LoggerMap;import imscportal.util.log.MyLogger;import imscportal.util.parameter.IMSCParameter;public class HttpChannel implements IHttpChannel { private MyLogger logger = LoggerMap.getLogger(this.getClass()); private URL url; public HttpChannel(String url) throws Exception { this.url = new URL(url); } public String sendPostRequest(String content) throws Exception { logger.debug("try to open http connection to: '" + this.url.getPath() + ":" + this.url.getPort() + "'"); HttpURLConnection conn = (HttpURLConnection) this.url.openConnection(); conn.setConnectTimeout(IMSCParameter .getHTTP_POST_REQUEST_CONNECT_TIMEOUT()); conn.setReadTimeout(IMSCParameter.getHTTP_POST_RESPONSE_READ_TIMEOUT()); conn.setDoOutput(true); conn.setRequestMethod("POST"); logger.debug("try to get output stream"); OutputStream output = conn.getOutputStream(); logger.debug("try to write '" + content + "'"); output.write(content.getBytes()); output.flush(); output.close(); logger.debug("try to get input stream"); BufferedReader reader = new BufferedReader(new InputStreamReader(conn .getInputStream())); String line; StringBuffer buffer = new StringBuffer(IMSCParameter .getHTTP_POST_RESPONSE_BUFFER_SIZE()); while ((line = reader.readLine()) != null) { buffer.append(line); } String value = buffer.toString(); logger.debug("get resposne: '" + value + "'"); value = URLDecoder.decode(value, IMSCParameter.getINTERNAL_CHARSET()); return value; }}
0 0
- 使用java代码发送HTTP Post请求
- HTTP JAVA代码发送POST请求
- java代码发送HTTP Post请求
- java发送http post请求
- Java发送HTTP请求-POST
- java发送http post请求
- java发送post请求代码
- Java代码发送POST请求
- JAVA 发送Http请求,GET、POST请求
- java代码发送http请求
- Java代码发送Http请求
- java发送HTTP GET POST请求
- java发送get、post http请求
- java发送http的get、post请求
- java发送http的get、post请求
- Java发送HTTP的POST请求
- java发送http的get、post请求
- java发送http的get、post请求
- 红米app的图标改变
- 各种终端问题解决办法
- Java的概述
- 常见的注册表操作及其含义
- android studio 下的debug模式下的keystore变成自己的keystore
- java代码发送HTTP Post请求
- CentOS 7 添加用户
- 网站负载均衡技术
- 020_ID生成策略_XML_配置
- iOS删除项目中未使用的图片资源
- 2、黑马程序员——继承
- 一点给新人的建议,请大家多指教批评
- opencv 基于灰度直方图的颜色迁移
- MASTUDIO 移动办公客户应用集锦