java拼接请求
来源:互联网 发布:ios开发用什么数据库 编辑:程序博客网 时间:2024/05/20 15:11
private JSONObject sendHttpsRequest(String pUrl,JSONObject postData)throws NoSuchAlgorithmException, KeyManagementException,IOException, JSONException {SSLContext sc = SSLContext.getInstance("SSL");sc.init(null, new TrustManager[] { new TrustAnyTrustManager() },new java.security.SecureRandom());StringBuffer mySign = new StringBuffer("");YoutuSign.appSign(APP_ID, SECRET_ID, SECRET_KEY,System.currentTimeMillis() / 1000 + EXPIRED_SECONDS,"", mySign);System.setProperty("sun.net.client.defaultConnectTimeout", "30000");System.setProperty("sun.net.client.defaultReadTimeout", "30000");//需要请求的地址URL url = new URL(pUrl);HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();connection.setSSLSocketFactory(sc.getSocketFactory());connection.setHostnameVerifier(new TrustAnyHostnameVerifier()); //请求方式采用post请求connection.setRequestMethod("POST");connection.setRequestProperty("accept", "*/*");connection.setRequestProperty("user-agent", "youtu-java-sdk");connection.setRequestProperty("Authorization", mySign.toString());connection.setDoOutput(true);connection.setDoInput(true);connection.setUseCaches(false);connection.setInstanceFollowRedirects(true);connection.setRequestProperty("Content-Type", "text/json");connection.connect(); // POST请求DataOutputStream out = new DataOutputStream(connection.getOutputStream());postData.put("app_id", APP_ID);out.write(postData.toString().getBytes("utf-8"));// 刷新、关闭out.flush();out.close();// 读取响应BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));String lines;StringBuffer resposeBuffer = new StringBuffer("");while ((lines = reader.readLine()) != null) {lines = new String(lines.getBytes(), "utf-8");resposeBuffer.append(lines);} // System.out.println(resposeBuffer+"\n");reader.close(); // 断开连接connection.disconnect();JSONObject respose = JSONObject.fromObject(resposeBuffer.toString());return respose;}
阅读全文
0 0
- java拼接请求
- java 拼接http请求
- JAVA根据请求拼接URL地址
- java拼接get请求的url请求地址
- Url请求get拼接
- Url请求get拼接
- 拼接请求网址
- httpGet()中拼接请求URL
- PHP 拼接HTTP请求字符串
- httpGet()中拼接请求URL
- HttpClient post请求拼接数字
- java 进行json字符串拼接及 接收请求的返回的对象
- 【JAVA】java字符串拼接
- Java 拼接 图片
- Java分割拼接图片
- java拼接图片
- Java中的字符串拼接
- Java分割拼接图片
- (JSP+Servlet)学生信息管理系统
- 用scikit-learn学习LDA主题模型
- 一个月薪字段的设计
- javase Connection interface
- POJ
- java拼接请求
- List 简单排序
- gcc编译出现segmentation fault的错误
- ansible-playbook实战之批量部署mysql主从同步
- 【Scikit-Learn 中文文档】概率校准
- 查询添加删除
- 多线程下载
- Swoole 实例二(Task功能)
- Thread、Runnable、Callable三种创建线程的简单示例及区别简介