老罗视频学习笔记。
一.客户端。
和上一篇java提供的接口传递数据基本类似。
sendHttpClientPost函数如下:
private static String sendHttpClientPost(String path,Map<String, String> params,String encode){
//进行一下封装
ArrayList<NameValuePair> list = new ArrayList<NameValuePair>();
if(params!=null && !params.isEmpty()){
for(Entry<String, String> entry : params.entrySet()){
list.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
}
try {
//实现将请求的参数封装到表单中,请求提交
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list,encode);
//使用post方式进行提交
HttpPost httpPost = new HttpPost(path);
httpPost.setEntity(entity);
//指定post请求
DefaultHttpClient client = new DefaultHttpClient();
//返回请求结果
HttpResponse httpResponse = client.execute(httpPost);
//判断请求结果
if(httpResponse.getStatusLine().getStatusCode() == 200)