接口自动化(第三回)HttpClient 初使用
1. get请求

package cn.edu.ccuc; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; import org.testng.annotations.Test; import org.apache.http.client.methods.HttpGet; public class MyHttpClient { @Test public void test3() throws Exception{ String result; String url1 = "http://www.baidu.com"; HttpGet get = new HttpGet(url1); HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(get); result = EntityUtils.toString(response.getEntity()); System.out.println("++++++++----------++++++++"); System.out.println(result); System.out.println("++++++++88888888+++++++"); } }
2. 通过配置文件传参

package cn.edu.ccuc; import org.testng.annotations.*; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import java.net.URI; import java.util.ResourceBundle; public class TestBundle { public String url; private ResourceBundle bundle; @BeforeTest public void beforeTest(){ bundle = ResourceBundle.getBundle("application"); url = bundle.getString("test.url"); System.out.println("111111111"); System.out.println(url); System.out.println("222222222"); } @Test public void test() throws Exception{ String res; String uri = bundle.getString("test.url"); } }
浙公网安备 33010602011771号