464_HttpURLConnection的post
来源:互联网 发布:c语言三元表达式 编辑:程序博客网 时间:2024/05/21 17:51
HttpURLConnection的post
new Thread(new Runnable() {
@Override
public void run() {
postByHttpURLConnection("http://op.juhe.cn/robot/index");
}
}).start();
public static String postByHttpURLConnection(String path) {
URL url = null;
try {
url = new URL(path);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");// 提交模式
// conn.setConnectTimeout(10000);//连接超时 单位毫秒
// conn.setReadTimeout(2000);//读取超时 单位毫秒
// 发送POST请求必须设置如下两行
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
// 获取URLConnection对象对应的输出流
PrintWriter printWriter = new PrintWriter(httpURLConnection.getOutputStream());
// 发送请求参数
printWriter.write("param=abc");//post的参数 xx=xx&yy=yy
// flush输出流的缓冲
printWriter.flush();
//开始获取数据
BufferedInputStream bis = new BufferedInputStream(httpURLConnection.getInputStream());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int len;
byte[] arr = new byte[1024];
while ((len = bis.read(arr)) != -1) {
bos.write(arr, 0, len);
bos.flush();
}
bos.close();
return bos.toString("utf-8");
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
0 0
- 464_HttpURLConnection的post
- 赵雅智_HttpURLConnection 的 get请求和post请求
- Android-上传图片(-)_HttpURLConnection
- android_29_post请求_HttpURLConnection
- android_27_get请求提交数据_HttpURLConnection
- jquery的post提交---$.post
- jquery的Post方法$.post()
- AJAX的post传递
- HttpURLConnection 的 POST 方法
- "post/get"的区别
- Post和Get的
- fsockopen的POST问题
- 发不出POST的内容
- POST Ajax 的使用
- php 的post
- Sqlmap的POST注入
- http的post请求
- ajax的post请求
- 7.6
- Atitit nodejs5 nodejs6 nodejs 7.2.1 新特性attialx总结
- 463_GreenDao框架使用
- 基于Ada语言的RTEMS应用开发
- HDU 2602 Bone Collector (0-1背包)
- 464_HttpURLConnection的post
- 465_画出部分透明的蒙版
- 数学知识
- How to Extend/Reduce LVM’s (Logical Volume Management) in Linux
- 466_简略findViewById
- STM32F4读写内部FLASH【使用库函数】
- 归并排序 Java
- android存储之preference和SQLite
- 467_去掉ScrollView的边缘阴影