public class Main {
public static void main(String[] args) throws IOException {
http_get();
http_post();
}
//---------------------------------------------------------------------------------------------------------
public static void http_get() throws IOException {
// 1:请求链接、接口地址: http://120. 78.xx.25: 8080/futureloan/ mvc/ api/ member/register
String url = "http://120.78.xx.25:8080/futureloan/mvc/api/member/register";
url += "?mobilephone=13666666666&pwd=123456®name=tom";
HttpGet get = new HttpGet(url);
HttpClient httpClient = HttpClients.createDefault();
HttpResponse response = httpClient.execute(get);
String result = EntityUtils. toString(response.getEntity());
System.out.println(result);
System.out.println("this is get
" );
}
public static void http_post() throws IOException {
// 1:请求链接、接口地址: http://120. 78.xx.25: 8080/futureloan/ mvc/ api/ member/register
String url = "http://120.78.xx.25:8080/futureloan/mvc/api/member/register";
HttpPost post = new HttpPost(url);
List<NameValuePair> parameters = new ArrayList<NameValuePair>() ;
parameters. add(new BasicNameValuePair( "mobilephone", "18300000000"));
parameters . add(new BasicNameValuePair("pwd", "123456"));
parameters . add(new BasicNameValuePair("regname", "tom"));
post.setEntity(new UrlEncodedFormEntity(parameters));
HttpClient httpClient = HttpClients.createDefault();
HttpResponse response = httpClient.execute(post);
String result = EntityUtils. toString(response.getEntity());
System.out.println(result);
System.out.println("this is post
" );
}
}