https请求样例
来源:互联网 发布:linux抓包工具 编辑:程序博客网 时间:2024/06/06 01:41
public static String sendPost(String str) throws Exception{
StringBuffer response = new StringBuffer();
int responseCode = -1;
//String postUrl = "http://111.13.56.193:9003/axj_http_sms/sms";
String postUrl = ConfigContainer.getSendurl();
try {
SSLContext sc;
sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[]{new TrustAnyTrustManager()},
new java.security.SecureRandom());
URL obj = new URL(postUrl);
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
con.setRequestMethod("POST");
// String urlParameters = mt.toString();
con.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
con.setRequestProperty("Connection", "Keep-Alive");
con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
con.setSSLSocketFactory(sc.getSocketFactory());
con.setHostnameVerifier(new TrustAnyHostnameVerifier());
con.setUseCaches(false);
con.setDoOutput(true);
// DataOutputStream wr = new
// DataOutputStream(con.getOutputStream());
OutputStream out = con.getOutputStream();
out.write(str.getBytes("UTF-8"));
out.flush();
out.close();
responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine = "";
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println("\t" + responseCode + "\t" + "POST" + "\t" + postUrl
+ "\t" + response.toString());
} catch (IOException e) {
// AppLogger.appDebug("###get发�?异常:"+responseCode+"\t"+"POST"+"\t"+mo.createUrlInfo()+"\t"+response.toString());
e.printStackTrace();
}
return response.toString();
}
StringBuffer response = new StringBuffer();
int responseCode = -1;
//String postUrl = "http://111.13.56.193:9003/axj_http_sms/sms";
String postUrl = ConfigContainer.getSendurl();
try {
SSLContext sc;
sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[]{new TrustAnyTrustManager()},
new java.security.SecureRandom());
URL obj = new URL(postUrl);
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
con.setRequestMethod("POST");
// String urlParameters = mt.toString();
con.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
con.setRequestProperty("Connection", "Keep-Alive");
con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
con.setSSLSocketFactory(sc.getSocketFactory());
con.setHostnameVerifier(new TrustAnyHostnameVerifier());
con.setUseCaches(false);
con.setDoOutput(true);
// DataOutputStream wr = new
// DataOutputStream(con.getOutputStream());
OutputStream out = con.getOutputStream();
out.write(str.getBytes("UTF-8"));
out.flush();
out.close();
responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine = "";
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println("\t" + responseCode + "\t" + "POST" + "\t" + postUrl
+ "\t" + response.toString());
} catch (IOException e) {
// AppLogger.appDebug("###get发�?异常:"+responseCode+"\t"+"POST"+"\t"+mo.createUrlInfo()+"\t"+response.toString());
e.printStackTrace();
}
return response.toString();
}
阅读全文
0 0
- https请求样例
- https请求
- HTTPS请求添加请求头
- HttpClient请求Https协议
- Java https请求 HttpsURLConnection
- curl https请求 解决方案
- Android 请求https 网址
- QT https post请求
- java 实现https请求
- HttpClient请求Https协议
- https请求绕过证书
- HttpClient请求Https协议
- java 实现https请求
- Qt 发送 https 请求
- java Https的请求
- java 发送 https请求
- ios https 请求讲解
- file_get_contents读取 https 请求
- 内建函数式接口
- web中文件下载用创建Iframe处理
- Android 横竖屏切换对Activity生命周期的影响
- 在javascript中==和===的区别
- dtree例子
- https请求样例
- 一致性哈希算法原理
- 配置OpenCV3.2.0和ViSP3.0.1于VS2015 Community
- 数组中的组合问题
- 微服务架构的优势与不足
- 简单排序算法(kotlin实现)
- echarts(三)折线柱状图
- 16
- 加密解密算法java实现(6)—RSA 分段加解密的例子