forked from LittleLory/codePool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpClientTest.java
More file actions
40 lines (32 loc) · 1.14 KB
/
HttpClientTest.java
File metadata and controls
40 lines (32 loc) · 1.14 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 utils.http;
import org.junit.Test;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class HttpClientTest {
private Map<String, String> headers = new HashMap<String, String>() {{
put("accept", "*/*");
put("connection", "Keep-Alive");
put("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
put("Accept-Charset", "utf-8");
put("contentType", "utf-8");
put("Content-Type", "application/x-www-form-urlencoded");
}};
private HttpClient httpClient;
public void init() {
//初始化HttpClientManager
HttpClientManager.init(400, 200);
//生成HttpClient实例
httpClient = HttpClient.instance(HttpClientManager.instance(), "test")
.connectRequestTimeout(1000)
.connectTimeout(1000)
.socketTimeout(5000)
.build();
}
@Test
public void test() throws IOException {
init();
String response = httpClient.doGet("http://www.baidu.com", headers, "uid=1×tamp=1510557964");
System.out.println(response);
}
}