
用Post传数组怎么做
推荐于2016-04-26 · 知道合伙人数码行家

知道合伙人数码行家
采纳数:117533
获赞数:517213
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注

展开全部
public String androidPost() { String rs = null; String path = "url/Android_JDBC_SH/AndroidLoginAction"; HttpPost hp = new HttpPost(path); //获取客户端,用来向服务器发出请求 DefaultHttpClient hc = new DefaultHttpClient(); try { //Default Constructor taking a name and a value BasicNameValuePair nm = new BasicNameValuePair("name", name); BasicNameValuePair pa = new BasicNameValuePair("password", password); List list = new ArrayList(); list.add(nm); list.add(pa); //构建向服务器发送的实体 HttpEntity entity = new UrlEncodedFormEntity(list); hp.setEntity(entity); //提交请求,获取服务器的响应 HttpResponse response = hc.execute(hp); if (response.getStatusLine().getStatusCode() == 200) { //获取响应实体 entity = response.getEntity(); rs = EntityUtils.toString(entity); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return rs; }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |