-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogout.java
More file actions
40 lines (36 loc) · 1.41 KB
/
Logout.java
File metadata and controls
40 lines (36 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package login;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class Logout
{
public Logout()
{
try
{
//action(表单)
// 建立连接
URL url = new URL("http://192.168.31.4:8080/?status=ok&url=");
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
// //设置连接属性
httpConn.setDoOutput(true);// 使用 URL 连接进行输出
httpConn.setDoInput(true);// 使用 URL 连接进行输入
httpConn.setUseCaches(false);// 忽略缓存
httpConn.setRequestMethod("POST");// 设置URL请求方法 (Method)
String requestString = "AuthenticateUser=&AuthenticatePassword=&Submit=Logout";
// 设置请求属性
// 获得数据字节数据,请求数据流的编码,必须和下面服务器端处理请求流的编码一致
byte[] requestStringBytes = requestString.getBytes("UTF-8");
// (如果不设此项,在传送序列化对象时,当WEB服务默认的不是这种类型时可能抛java.io.EOFException)
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
// 建立输出流,并写入数据
OutputStream outputStream = httpConn.getOutputStream(); //包含connect()方法
outputStream.write(requestStringBytes);
outputStream.close();
InputStream inStream=httpConn.getInputStream();
}
catch (Exception e)
{}
}
}