java http调用方式get post 包含带header
2015-12-09 16:45
555 查看
public String CreateUser(){ BufferedReader reader = null; String result = null; String httpUrl="http://xxx.xxx.xxx/xxx?"; StringBuffer sbf = new StringBuffer(); String httpArg="xxx=&xxx="; httpUrl = httpUrl + "" + httpArg; try { URL url = new URL(httpUrl); HttpURLConnection connection = (HttpURLConnection) url .openConnection(); connection.setRequestMethod("POST"); //POST,Get // HTTP header //connection.setRequestProperty("Host","upcaiyun2.com"); connection.connect(); InputStream is = connection.getInputStream(); reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); String strRead = null; while ((strRead = reader.readLine()) != null) { sbf.append(strRead); sbf.append("\r\n"); } reader.close(); result = sbf.toString(); } catch (Exception e) { e.printStackTrace(); } return result; }
相关文章推荐
- http://cssload.net/----动画
- Java——常见的HTTP状态码:
- Volley的初级使用(从网络下载图片)
- 用httpPost对JSON发送和接收的例子
- memcached 网络模型 --转载处:
- 质问微软 WP8.1开发HTTPS 真费劲
- UVA-10779 Collectors Problem (网络流建模)
- UDP和TCP
- 操作系统与网络实现 之十一
- 操作系统与网络实现 之十一
- 网络虚拟化之FlowVisor:网络虚拟层(中)
- 分享一些灵活高效运用OkHttp的技巧和强有力的内省。
- [Servlet&JSP] HttpServletRequest的使用
- VirtualBox 四种网络连接
- NetFlow网络流量监测技术的应用和设计(转载)
- httpClient4.5创建连接池进行post请求
- linux基础(六)----linux命令系统学习----网络操作命令
- linux基础(六)----linux命令系统学习----网络操作命令
- HttpClient的使用(模拟登录)
- TCP与UDP的区别