使用HttpURLConnection进行POST方式提交
2012-12-18 16:58
579 查看
用HttpURLConnection进行Post方式提交,下面给出一个例子 URL url = null; HttpURLConnection httpurlconnection = null; try { url = new URL("http://xxxx"); httpurlconnection = (HttpURLConnection) url.openConnection(); httpurlconnection.setDoOutput(true); httpurlconnection.setRequestMethod("POST"); String username="username=02000001"; httpurlconnection.getOutputStream().write(username.getBytes()); httpurlconnection.getOutputStream().flush(); httpurlconnection.getOutputStream().close(); int code = httpurlconnection.getResponseCode(); System.out.println("code " + code); } catch(Exception e) { e.printStackTrace(); } finally { if(httpurlconnection!=null) httpurlconnection.disconnect(); } 其中HttpURLConnection中的addRequestProperty方法,并不是用来添加Parameter 的,而是用来设置请求的头信息,比如: setRequestProperty("Content-type","text/html"); setRequestProperty("Connection", "close"); setRequestProperty("Content-Length",xxx); 当然如果不设置的话,可以走默认值,上面的例子中就没有进行相关设置,但是也可以正确执行
相关文章推荐
- 使用HttpURLConnection进行POST方式提交
- 使用HttpURLConnection进行POST方式提交
- HttpURLconnection使用POST方式提交JSON数据给服务器
- 使用HttpURLConnection通过POST方式提交请求数据,并上传文件
- java Struts2 使用HttpURLConnection进行post提交乱码
- HttpURLconnection使用POST方式提交JSON数据给服务器
- 做一个程序来查询手机号码的归属地(使用的是HttpURLConnection的post提交方式)
- 使用HttpUrlConnection进行post 提交
- Android学习之Http使用Post方式进行数据提交
- android 使用HttpURLConnection方式提交get/post请求
- 【黑马Android】(05)短信/查询和添加/内容观察者使用/子线程网络图片查看器和Handler消息处理器/html查看器/使用HttpURLConnection采用Post方式请求数据/开源项目
- Android学习之Http使用Post方式进行数据提交(普通数据和Json数据)
- Android开发之使用HttpURLConnection进行POST请求
- 使用HttpURLConnection和使用HttpClient方式请求网络采用get方式和post方式请求数据
- 写一个程序用来查询手机号码的归属地(使用的是HttpURLConnection的get提交方式)
- HttpURLConnection form-data的post方式,提交图片信息
- Java 通过HttpURLConnection Post方式提交xml,并从服务端返回数据
- Android Http使用Post方式进行数据提交
- JAVA HttpURLConnection Post方式提交传递参数
- Android学习之Http使用Post方式进行数据提交