post 请求
来源:互联网 发布:淘宝大学教程百度云 编辑:程序博客网 时间:2024/06/10 18:05
new Thread(){
public void run() {
//?userName="+name+"&passWord="+pwd
String path="http://169.254.135.196:8080/LogServer/servlet/LogServlet";
String data ="userName="+name+"&passWord="+pwd;
//参数是请求的地址
try {
URL url = new URL(path);
//得到HttpURLConnection 对像
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//设置它的请求方式
connection.setRequestMethod("POST");
//设轩它的连接超时时间
connection.setConnectTimeout(5000);
//代表允客户端给服务器写内容
connection.setDoInput(true);
//把参数写给服务器
connection.getOutputStream().write(data.getBytes());
//得到服务器给客户端返回的状态码 200 304 307 404 500
int responseCode = connection.getResponseCode();
baos = new ByteArrayOutputStream();
//请求服务器成功
if(responseCode==200){
//得到服务器返回的流 其实就是数据
InputStream is = connection.getInputStream();
byte[] arr = new byte[1024];
int len;
while((len=is.read(arr))!=-1){
//baos.write(arr);
baos.write(arr, 0, len);
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
public void run() {
//?userName="+name+"&passWord="+pwd
String path="http://169.254.135.196:8080/LogServer/servlet/LogServlet";
String data ="userName="+name+"&passWord="+pwd;
//参数是请求的地址
try {
URL url = new URL(path);
//得到HttpURLConnection 对像
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//设置它的请求方式
connection.setRequestMethod("POST");
//设轩它的连接超时时间
connection.setConnectTimeout(5000);
//代表允客户端给服务器写内容
connection.setDoInput(true);
//把参数写给服务器
connection.getOutputStream().write(data.getBytes());
//得到服务器给客户端返回的状态码 200 304 307 404 500
int responseCode = connection.getResponseCode();
baos = new ByteArrayOutputStream();
//请求服务器成功
if(responseCode==200){
//得到服务器返回的流 其实就是数据
InputStream is = connection.getInputStream();
byte[] arr = new byte[1024];
int len;
while((len=is.read(arr))!=-1){
//baos.write(arr);
baos.write(arr, 0, len);
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
阅读全文
0 0
- post请求
- POST请求
- POST请求
- POST请求
- post请求
- POST请求
- post请求
- POST请求
- post请求
- post 请求
- post请求
- post请求
- POST请求
- POST请求
- post请求
- post请求
- post请求
- post请求
- 手把手教你系列
- 网页字体缩放样式-webkit-text-size-adjust
- 51单片机控制引脚
- 使用Hadoop运行WorldCount示例
- 【Android】 美团点评校招一面17/9/21
- post 请求
- 极路由+锐捷校园网小白使用教程
- AngularJS
- PullToRefreshListView绘制头布局
- 数据结构的栈与队列
- WCF学习过程和心得(一)
- ImageView自定义圆形图片
- 数据库连接池原理(一)
- 邻接表-数组的实现