android项目中有部下代码访问服务器,请问在服务器servlet中如何获得在android中传过去的键和值?public static boolean httpPostClient(String uri,Map<String,String> params)throws Exception{
boolean flag=false;
List<NameValuePair> list=new ArrayList<NameValuePair>();
if(params!=null&&!params.isEmpty()){
for(Map.Entry<String, String> map:params.entrySet()){
list.add(new BasicNameValuePair(map.getKey(), map.getValue()));
}
}
HttpClient client=new DefaultHttpClient();
HttpPost request=new HttpPost(uri);
HttpResponse response=client.execute(request);
UrlEncodedFormEntity entity=new UrlEncodedFormEntity(list,HTTP.UTF_8);
request.setEntity(entity);
if(response.getStatusLine().getStatusCode()==200){
flag=true;
}
System.out.println("flag="+flag);
return flag;
}准备传进去的参数map的键和值都不一样。例如:灯泡=2个,插座=3个。
请问如何在servlet中取得我传过去的键和值?
boolean flag=false;
List<NameValuePair> list=new ArrayList<NameValuePair>();
if(params!=null&&!params.isEmpty()){
for(Map.Entry<String, String> map:params.entrySet()){
list.add(new BasicNameValuePair(map.getKey(), map.getValue()));
}
}
HttpClient client=new DefaultHttpClient();
HttpPost request=new HttpPost(uri);
HttpResponse response=client.execute(request);
UrlEncodedFormEntity entity=new UrlEncodedFormEntity(list,HTTP.UTF_8);
request.setEntity(entity);
if(response.getStatusLine().getStatusCode()==200){
flag=true;
}
System.out.println("flag="+flag);
return flag;
}准备传进去的参数map的键和值都不一样。例如:灯泡=2个,插座=3个。
请问如何在servlet中取得我传过去的键和值?
解决方案 »
- 安卓4关机画面不出现怎么办?
- 请问addView进来的东西怎么填满add它的父容器?
- 新手提问:要在软件开启的时候像androidQQ那样有一幅图片显示一段时间后再进入主界面如何实现?
- spinner 改变屏幕方向后,弹出选择框消失?
- 关于实现发送带有表情的文字的问题
- Android应用程序 单例对象会不会被回收?
- android监听器
- SQLiteOpenHelper初始化的时候,context怎么填写呢
- 关于“tabhost”切换问题
- 求大神支招,数据库查询 cursor.moveToNext()直接报错,cursor不为空
- 【求救】如何利用gridview实现不规则的布局
- 各位帮我看看这个小程序,在java编辑器可以编译运行获取到数据,把方法里面的代码移植到一个安卓小项目就无法获取到文件里面的内容,各位大神,帮帮我这新手...
request.getParameterNames()
post在正文中提交参数值对
这样服务器自然就会取得到