Http与网络通信(GET和POST方式)
来源:互联网 发布:怎么自己开淘宝网店 编辑:程序博客网 时间:2024/05/21 10:54
1. 使用Http的Get方式读取网络数据
URL url = new URL("");
URLConnection connection = url.openConnection();
InputStream is = connection.getInputStream();
InputStreamReader isr = new InputStreamReader(is,"UTF-8");
BufferedReader br = new BufferedReader(isr);
String line = null;
StringBuilder builder = new StringBuilder();
while((line=br.readLine())!=null){
builder.append(line);
}
br.close();
isr.close();
is.close();
System.out.println(builder.toString)
2. 使用Http的Post方式与网络交互通信
URL url = new URL("url");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.addRequestProperty("encoding","UTF-8");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
OutputStream os = connection.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os);
BufferedWriter bw = new BufferedWriter(osw);
bw.write("参数");
bw.flush();
InputStream is = connection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line =null;
StringBuilder builder =new StringBuilder();
while((line = br.readLine())!=null){
builder.append(line);
}
bw.close();
osw.close();
os.close();
br.close();
isr.close();
is.close();
System.out.println(builder.toString());
URL url = new URL("");
URLConnection connection = url.openConnection();
InputStream is = connection.getInputStream();
InputStreamReader isr = new InputStreamReader(is,"UTF-8");
BufferedReader br = new BufferedReader(isr);
String line = null;
StringBuilder builder = new StringBuilder();
while((line=br.readLine())!=null){
builder.append(line);
}
br.close();
isr.close();
is.close();
System.out.println(builder.toString)
2. 使用Http的Post方式与网络交互通信
URL url = new URL("url");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.addRequestProperty("encoding","UTF-8");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
OutputStream os = connection.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os);
BufferedWriter bw = new BufferedWriter(osw);
bw.write("参数");
bw.flush();
InputStream is = connection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line =null;
StringBuilder builder =new StringBuilder();
while((line = br.readLine())!=null){
builder.append(line);
}
bw.close();
osw.close();
os.close();
br.close();
isr.close();
is.close();
System.out.println(builder.toString());
阅读全文
0 0
- Http与网络通信(GET和POST方式)
- 网络传输协议(http协议/请求和响应/get方式与post方式)
- Unity3D HTTP协议 网络通信 post get
- android使用Http的Post方式与网络交互通信
- JAVA:使用 HTTP 的 Post 方式与网络交互通信
- 使用http的post方式与网络交互通信
- Http GET和Http Post发送方式
- Android之Http通信GET与POST
- java33.HTTP通信------使用Http的Post方式与网络交互通信
- Java使用HTTP的get方法读取网络数据、使用post方法与网络交互通信
- HTTP请求方式:get与post
- Android 使用 HttpClient 进行网络通信,包括Get方式和Post方式
- Android 使用 HttpClient 进行网络通信,包括Get方式和Post方式
- Android 使用 HttpClient 进行网络通信,包括Get方式和Post方式
- Android 使用 HttpClient 进行网络通信,包括Get方式和Post方式(转)
- Android HttpURLConnection(Get,Post方式)进行网络通信 获取数据和网络图片
- android中HTTP协议访问网络及其方式及其http的GET和POST的优缺点
- HTTP get和post方式的区别
- OpenLayers 加载静态图片
- jQuery学习笔记6
- 关于升级swif3.0的一些东西(续)
- AngularJS系列之select下拉选择第一个选项为空白的解决办法
- 【C】初学习之库函数——通用的实用工具<stdlib.h>之伪随机序列生成函数
- Http与网络通信(GET和POST方式)
- 求最短路即次短路模板,一条边可以重复走的HDU6181
- [笔记分享] [OS] Linux的时间管理
- leetcode75: Sort Colors
- R语言对高频交易订单流进行建模分析 1
- weex 学习历程
- 报错`mobx.map` is deprecated, use `new ObservableMap` or `mobx.observable.map`instead
- 1015:大小写问题
- var 与let const比较