HttpURLConnection发送post请求信息

	public static void testHttpQuest() {
		// {‘pfxInfo‘:‘no‘,‘isPfx‘:‘no‘,‘signInfo‘:‘中文‘,‘passCode‘:‘‘,‘signType‘:‘yes‘}
		logger.info("开始下载更新CRL");
		// 创建URL 对象
		URL url = null;
		byte[] b = null;
		FileOutputStream fos = null;
		InputStream is = null;
		HttpURLConnection httpUrlConnection = null;

		try {
			 url = new
			 URL("http://101.201.80.221:8899/VerifyInfoService/doSign");
//			url = new URL("http://localhost:8888//VerifyInfoService/doSign");
			// 获取 httpUrl连接
			httpUrlConnection = (HttpURLConnection) url.openConnection();

			httpUrlConnection.setRequestMethod("POST");
			httpUrlConnection.setDoInput(true);
			httpUrlConnection.setDoOutput(true);
			String params = "signedInfoValue={‘pfxInfo‘:‘no‘,‘isPfx‘:‘no‘,‘signInfo‘:‘中文‘,‘passCode‘:‘‘,‘signType‘:‘yes‘}";
			httpUrlConnection.setRequestProperty("accept", "*/*");
			httpUrlConnection.setRequestProperty("connection", "Keep-Alive");
			httpUrlConnection.setRequestProperty("Content-Type",
					"application/x-www-form-urlencoded");
			 httpUrlConnection.connect();
			OutputStreamWriter outStream = new OutputStreamWriter(
					httpUrlConnection.getOutputStream(), "UTF-8");
			outStream.write(params);
			outStream.flush();
			outStream.close();
			BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(  
					httpUrlConnection.getInputStream())); 

			 String line;  
			 StringBuffer responseResult = new StringBuffer();  

	            while ((line = bufferedReader.readLine()) != null) {  
	            	responseResult.append(line); 
	            }  
	            System.out.println(responseResult.toString());

			int responseCode = httpUrlConnection.getResponseCode();  
			System.out.println(responseCode);
			httpUrlConnection.disconnect();
		} catch (MalformedURLException e) {
			logger.info("下载CRL列表失败!");
			e.printStackTrace();
		} catch (IOException e) {
			logger.info("下载CRL列表失败!");
			e.printStackTrace();
		}
	}
时间: 2024-08-29 12:40:30

HttpURLConnection发送post请求信息的相关文章

使用httpclient实现http链接池与使用HttpURLConnection发送http请求的方法与性能对比

使用httpclient实现http链接池与使用HttpURLConnection发送http请求的方法与性能对比 在项目中需要使用http调用接口,实现了两套发送http请求的方法,一个是使用apache的httpclient提供的http链接池来发送http请求,另一个是使用java原生的HttpURLConnection来发送http请求,并对两者性能进行了对比. 使用httpclient中的链接池发送http请求 使用最新的4.5.2版httpclient进行实现.在maven中引入 <

HttpUrlConnection发送url请求(后台springmvc)

1.HttpURLConnection发送url请求 public class JavaRequest { private static final String BASE_URL = "http://localhost:8080/dsdemo/"; public static String userToken = null; public static String problemName = null; public static String sendPost(String su

【JAVA】通过URLConnection/HttpURLConnection发送HTTP请求的方法

Java原生的API可用于发送HTTP请求 即java.net.URL.java.net.URLConnection,JDK自带的类: 1.通过统一资源定位器(java.net.URL)获取连接器(java.net.URLConnection) 2.设置请求的参数 3.发送请求 4.以输入流的形式获取返回内容 5.关闭输入流 封装请求类 1 package com.util; 2 3 import java.io.BufferedReader; 4 import java.io.IOExcept

HttpURLConnection 发送PUT请求 json请求体 与服务端接收

public void testHttp() { String result = ""; try { URL postURL = new URL("http://localhost:8080/webTest/TestSerlvte"); HttpURLConnection conn = (HttpURLConnection) postURL.openConnection(); conn.setDoOutput(true); conn.setDoInput(true)

java 使用原生HttpURLConnection发送post请求

import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.text.SimpleDateFormat; import java.util.Cale

Java利用HttpURLConnection发送post请求

URL url = null; HttpURLConnection http = null; try { url = new URL(urls); http = (HttpURLConnection) url.openConnection(); http.setDoInput(true); http.setDoOutput(true); http.setUseCaches(false); http.setConnectTimeout(50000);//设置连接超时 //如果在建立连接之前超时期满

java 常见几种发送http请求案例

1 import java.io.FileOutputStream; 2 import java.io.IOException; 3 import java.io.InputStream; 4 import java.io.InputStreamReader; 5 import java.io.OutputStreamWriter; 6 import java.io.UnsupportedEncodingException; 7 import java.net.HttpURLConnection

Java发布webservice应用并发送SOAP请求调用

webservice框架有很多,比如axis.axis2.cxf.xFire等等,做服务端和做客户端都可行,个人感觉使用这些框架的好处是减少了对于接口信息的解析,最主要的是减少了对于传递于网络中XML的解析,代价是你不得不在你的框架中添加对于这些框架的依赖.个人观点是:服务端使用这些框架还行,如果做客户端,没必要使用这些框架,只需使用httpclient即可. 一.创建并发布一个简单的webservice应用 1.webservice 代码: import javax.jws.WebMethod

每天一个linux命令13之curl发送http请求

一.get请求 curl "http://www.baidu.com"  如果这里的URL指向的是一个文件或者一幅图都可以直接下载到本地 curl -i "http://www.baidu.com"  显示全部信息 curl -l "http://www.baidu.com" 只显示头部信息 curl -v "http://www.baidu.com" 显示get请求全过程解析 wget "http://www.ba