post方法
来源:互联网 发布:mysql 关闭数据库 编辑:程序博客网 时间:2024/05/22 00:24
public static String doPost(String urlString, String param) {
URL url = null;
HttpURLConnection URLConn = null;
OutputStreamWriter out = null;
BufferedReader reader = null;
StringBuffer resultBuf = new StringBuffer();
try {
url = new URL(urlString);
URLConn = (HttpURLConnection) url.openConnection();
URLConn.setConnectTimeout(40000);
URLConn.setReadTimeout(40000);
URLConn.setDoInput(true);
URLConn.setDoOutput(true);
URLConn.setRequestMethod("POST");
URLConn.setUseCaches(false);
URLConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
URLConn.connect();
out = new OutputStreamWriter(URLConn.getOutputStream());
out.write(param.toString());
out.flush();
reader = new BufferedReader(new InputStreamReader(URLConn.getInputStream(), "UTF-8"));
String temp = null;
while ((temp = reader.readLine()) != null) {
resultBuf.append(temp);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (reader != null) {
reader.close();
}
if (out != null) {
out.close();
}
if (URLConn != null) {
URLConn.disconnect();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return resultBuf.toString();
}
URL url = null;
HttpURLConnection URLConn = null;
OutputStreamWriter out = null;
BufferedReader reader = null;
StringBuffer resultBuf = new StringBuffer();
try {
url = new URL(urlString);
URLConn = (HttpURLConnection) url.openConnection();
URLConn.setConnectTimeout(40000);
URLConn.setReadTimeout(40000);
URLConn.setDoInput(true);
URLConn.setDoOutput(true);
URLConn.setRequestMethod("POST");
URLConn.setUseCaches(false);
URLConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
URLConn.connect();
out = new OutputStreamWriter(URLConn.getOutputStream());
out.write(param.toString());
out.flush();
reader = new BufferedReader(new InputStreamReader(URLConn.getInputStream(), "UTF-8"));
String temp = null;
while ((temp = reader.readLine()) != null) {
resultBuf.append(temp);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (reader != null) {
reader.close();
}
if (out != null) {
out.close();
}
if (URLConn != null) {
URLConn.disconnect();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return resultBuf.toString();
}
0 0
- $.post方法
- Post方法
- post方法
- post方法
- $.post()方法
- jquery的Post方法$.post()
- get与post方法
- HttpURLConnection 的 POST 方法
- 模拟POST方法
- Post方法Servlet跳转
- Http方法 GET/POST
- widow open post方法
- get与post方法 .
- HTTP POST 方法
- HttpClient中的POST方法
- jQuery ajax --post() 方法
- $.post()方法使用
- jQuery.post() 方法用法
- http详解地址--http下午茶
- IOS初级:NSUserDefaults
- sha1加密
- linux命令七:crontab
- GRE作文备考——法律类
- post方法
- 接着刷题
- Android bluetooth 蓝牙开发/蓝牙协议/蓝牙通信
- java取整和java四舍五入方法
- 【转载】恼人的函数指针(一)
- leetcode 4 -- Median of Two Sorted Arrays
- MySQL学习第一弹:mysql安装
- 中国大陆新身份证号码算法[18位身份证号码生成器]
- Frostwire工程项目的建立