HttpTest.java 1.93 KB
package com.monitor;

import com.monitor.common.util.HttpRestClient;
import org.apache.commons.net.telnet.TelnetClient;
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.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * 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();
    }

}