-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpUtil.java
More file actions
137 lines (137 loc) · 5.23 KB
/
HttpUtil.java
File metadata and controls
137 lines (137 loc) · 5.23 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.BinaryHttpResponseHandler;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
/**
* Function: TODO ADD FUNCTION. <br/>
* Date: 2015-1-16 下午3:03:30 <br/>
*
* @author YeMeng
*/
public class HttpUtil {
private static AsyncHttpClient client = new AsyncHttpClient(); // 实例话对象
static {
client.setEnableRedirects(true);
client.setTimeout(60000); // 设置链接超时,如果不设置,默认为10s
if (!SpUtil.getStringSharedPerference("authorization", "").equals("")) {
setAuthHeader();
}
}
public static void get(String urlString, AsyncHttpResponseHandler res) // 用一个完整url获取一个string对象
{
ELog.e(urlString);
client.get(urlString, res);
}
public static void get(String urlString, RequestParams params,
AsyncHttpResponseHandler res) // url里面带参数
{
ELog.e(urlString);
client.get(urlString, params, res);
}
public static void get(String urlString, JsonHttpResponseHandler res) // 不带参数,获取json对象或者数组
{
ELog.e(urlString);
client.get(urlString, res);
}
public static void get(String urlString, RequestParams params,
JsonHttpResponseHandler res) // 带参数,获取json对象或者数组
{
ELog.e(urlString);
client.get(urlString, params, res);
}
public static void get(String uString, BinaryHttpResponseHandler bHandler) // 下载数据使用,会返回byte数据
{
ELog.e(uString);
client.get(uString, bHandler);
}
public static void post(String urlString, AsyncHttpResponseHandler res) // 用一个完整url获取一个string对象
{
ELog.e(urlString);
client.post(urlString, res);
}
public static void post(String urlString, RequestParams params,
AsyncHttpResponseHandler res) // url里面带参数
{
ELog.e(urlString);
params.setContentEncoding("utf-8");
client.post(urlString, params, res);
}
public static void post(String urlString, JsonHttpResponseHandler res) // 不带参数,获取json对象或者数组
{
ELog.e(urlString);
client.post(urlString, res);
}
public static void post(String urlString, RequestParams params,
JsonHttpResponseHandler res) // 带参数,获取json对象或者数组
{
ELog.e(urlString);
client.post(urlString, params, res);
}
public static void post(String uString, BinaryHttpResponseHandler bHandler) // 下载数据使用,会返回byte数据
{
ELog.e(uString);
client.post(uString, bHandler);
}
public static void put(String urlString, AsyncHttpResponseHandler res) // 用一个完整url获取一个string对象
{
ELog.e(urlString);
client.put(urlString, res);
}
public static void put(String urlString, RequestParams params,
AsyncHttpResponseHandler res) // url里面带参数
{
ELog.e(urlString);
client.put(urlString, params, res);
}
public static void put(String urlString, JsonHttpResponseHandler res) // 不带参数,获取json对象或者数组
{
ELog.e(urlString);
client.put(urlString, res);
}
public static void put(String urlString, RequestParams params,
JsonHttpResponseHandler res) // 带参数,获取json对象或者数组
{
ELog.e(urlString);
client.put(urlString, params, res);
}
public static void put(String uString, BinaryHttpResponseHandler bHandler) // 下载数据使用,会返回byte数据
{
ELog.e(uString);
client.put(uString, bHandler);
}
public static void delete(String urlString, AsyncHttpResponseHandler res) // 用一个完整url获取一个string对象
{
ELog.e(urlString);
client.delete(urlString, res);
}
// public static void delete(String urlString, RequestParams params,
// AsyncHttpResponseHandler res) // url里面带参数
// {
// client.delete(urlString, params, res);
// }
public static void delete(String urlString, JsonHttpResponseHandler res) // 不带参数,获取json对象或者数组
{
ELog.e(urlString);
client.delete(urlString, res);
}
// public static void delete(String urlString, RequestParams params,
// JsonHttpResponseHandler res) // 带参数,获取json对象或者数组
// {
// client.delete(urlString, params, res);
// }
public static void delete(String uString, BinaryHttpResponseHandler bHandler) // 下载数据使用,会返回byte数据
{
ELog.e(uString);
client.delete(uString, bHandler);
}
public static AsyncHttpClient getClient() {
return client;
}
public static AsyncHttpClient setAuthHeader() {
client.removeHeader("Authorization");
client.addHeader(
"Authorization", SpUtil.getStringSharedPerference("authorization", ""));
return client;
}
}