HttpTest.java
2.16 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
package com.monitor;
import com.monitor.common.util.HttpRestClient;
import org.apache.commons.net.telnet.TelnetClient;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.Socket;
/**
* Created by fruwei on 2016/7/5.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath*:META-INF/spring/spring*.xml"})
@PropertySource({
"classpath:*.properties"})
public class HttpTest {
@Autowired
HttpRestClient httpRestClient;
@Test
public void test() throws IOException {
// String rel=httpRestClient.defaultGet("http://192.168.102.205:8080/gateway/guang/api/v1/category/get?app_version=4.4.0.1605260001&client_secret=03c54a201923249c5305bc9312276058&client_type=iphone&gender=1%2C3&os_version=8.4&screen_size=320x568&udid=778b9937f128b9077ebc76b782f46a04e06911d4&v=7&yh_channel=1",String.class);
String rel = "";
// rel = httpRestClient.defaultGet("http://192.168.102.205:8080/gateway", String.class);
// rel = httpRestClient.defaultGet("http://192.168.102.222:22222/?v=1", String.class);
// System.out.println("#################################### \n" + rel);
TelnetClient telnet = new TelnetClient();
telnet.connect("192.168.102.212", 22222);
InputStream in = telnet.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i = -1;
while ((i = in.read()) != -1) {
baos.write(i);
}
System.out.println("################# " + baos.toString());
in.close();
baos.close();
telnet.disconnect();
}
}