Httpclient---------框架

http://hc.apache.org/

-----------------------------------------------------------------------------------------

package com.course.httpclient;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.testng.annotations.Test;
import java.io.IOException;
public class MyHttpClient {
@Test
public void test1() throws IOException {
//用来存放我们的结果
System.out.println("");
String result;
HttpGet get=new HttpGet("http://127.0.0.1:8080/pinter/index");
//用来执行get方法的
HttpClient client=new DefaultHttpClient();
HttpResponse response=client.execute(get);
result=EntityUtils.toString(response.getEntity(),"utf-8") ;
System.out.println(result);
}
}
posted on 2021-08-05 14:14  thy520  阅读(65)  评论(0编辑  收藏  举报