HttpClient使用

HttpClient使用

注意请求参数!!!

// 创建HttpClient模板
HttpClient client = new DefaultHttpClient();  
//创建post模板
HttpPost post = new HttpPost("http://cnivi.com.cn/login");
//创建json模板
List<NameValuePair> formparams = new ArrayList<NameValuePair>();  
//添加json内容
formparams.add(new BasicNameValuePair("account", ""));  
formparams.add(new BasicNameValuePair("password", ""));
//创建entity体
HttpEntity reqEntity = new UrlEncodedFormEntity(formparams, "utf-8");
//执行post请求
HttpResponse response = client.execute(post);
//打印响应体
HttpEntity resEntity = response.getEntity();  
String message = EntityUtils.toString(resEntity, "utf-8");  
System.out.println(message);

HttpClient使用

上一篇:cypress 自动化测试(文件上传)


下一篇:密钥认证和https证书脚本