void testPackage(String urlStr) { try { StringBuffer xmlBuffer = new StringBuffer(); xmlBuffer.append("<params>"); xmlBuffer.append("<id>"); xmlBuffer.append("1"); xmlBuffer.append("</id>"); xmlBuffer.append("</params>"); URL url = new URL(urlStr); URLConnection con = url.openConnection(); con.setDoOutput(true); con.setRequestProperty("Pragma:", "no-cache"); con.setRequestProperty("Cache-Control", "no-cache"); con.setRequestProperty("Content-Type", "text/xml"); /* * OutputStreamWriter out = new OutputStreamWriter( * con.getOutputStream()); */ String xmlInfo = "params=" + xmlBuffer.toString(); PrintWriter out = new PrintWriter(con.getOutputStream()); out.print(xmlInfo); // out.print(URLEncoder.encode(xmlInfo,"UTF-8")); // out.write(new String(xmlInfo.getBytes("UTF-8"))); out.flush(); out.close(); BufferedReader br = new BufferedReader(new InputStreamReader( con.getInputStream())); String line = ""; for (line = br.readLine(); line != null; line = br.readLine()) { System.out.println(line); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
相关推荐
java语言后台请求网站操作 java中main方法发送httpPost请求
java代码发送JSON格式的httpPOST请求
如果您正在寻找一份JAVA客户端发送POST请求的示例代码,那么我们的资源库将为您提供一切所需。本资源库提供了一份完整的JAVA客户端发送POST请求的示例代码,可以帮助您快速了解如何使用JAVA客户端发送POST请求,同时...
java发送http/https请求(get/post)代码,java 通过发送json,post请求,返回json数据的方法 java 通过发送json,post请求,返回json数据的方法
java 通过发送json,post请求,返回json数据的方法 java 通过发送json,post请求,返回json数据的方法
使用java发送get和post请求实践
java HttpClient 发送GET请求和带有表单参数的POST请求教程例子
用java编写了http Post的请求代码,通过发送请求的 URL,获取远程资源的响应结果,入参为json字符串。使用到httpPost,CloseableHttpClient
Java发送http请求、https请求,post和get都支持
java代码-使用java解决带参发送post方式的http请求的源代码 ——学习参考资料:仅用于个人学习使用!
java实现get请求post请求,文件传输 /** * 发送https请求 * @param requestUrl 请求地址 * @param requestMethod 请求方式(GET、POST) * @param outputStr 提交的数据 * @return 返回微信服务器响应的信息 ...
java发送https请求,解决了数组证书的问题,所依赖的jar都有
java模拟HTTP发送post和get请求工具类,使用httpClient类
HTTP发送POST请求的工具类
自己项目里的,可用
java http-post form表单客户端请求代码,拿过去直接应用即可
Java模拟post请求传上传文件(文件流做参)、下载文件、好使的。
java的get和post请求,获取json的工具类,https时会存在ssl校验的问题,工具会自动去除ssl校验。
java http 发送xml报文(java发送xml报文实例+参数)java http 发送xml报文java http 发送xml报文(java发送xml报文实例+参数)
java后台实现 get post 提交.zip