Android开发中如何执行POST请求
2013-05-23 20:59
417 查看
String uriAPI = "http://192.168.1.100:8080/test/test.jsp"; //这是我测试的本地,大家可以随意改 /*建立HTTPost对象*/ HttpPost httpRequest = new HttpPost(uriAPI); /* * NameValuePair实现请求参数的封装 */ List <NameValuePair> params = new ArrayList <NameValuePair>(); params.add(new BasicNameValuePair("u", "沈大海")); params.add(new BasicNameValuePair("p", "123")); try { /* 添加请求参数到请求对象*/ httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); /*发送请求并等待响应*/ HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest); /*若状态码为200 ok*/ if(httpResponse.getStatusLine().getStatusCode() == 200) { /*读返回数据*/ String strResult = EntityUtils.toString(httpResponse.getEntity()); mTextView1.setText(strResult); } else { mTextView1.setText("Error Response: "+httpResponse.getStatusLine().toString()); } } catch (ClientProtocolException e) { mTextView1.setText(e.getMessage().toString()); e.printStackTrace(); } catch (IOException e) { mTextView1.setText(e.getMessage().toString()); e.printStackTrace(); } catch (Exception e) { mTextView1.setText(e.getMessage().toString()); e.printStackTrace(); } ////大家能根据这个代码实现个android用户登陆吗?
相关文章推荐
- Android开发中如何执行POST请求
- android 如何执行大批量post请求?
- Android开发技术网络篇之── http协议post请求方式
- Android开发 httpClient post方法请求tomcat服务器实现注册登陆
- Android 开发中使用回调执行网络请求
- [Android开发常见问题-4] RunTime.exec()如何以root权限执行多条指令?
- Android开发 httpClient post方法请求tomcat服务器实现注册登陆
- 【Android网络请求】如何使用Volley发送POST请求
- Android执行POST请求
- Android开发网络请求之GET和POST
- Android开发 HTTP 发送 Post 与 Get 请求
- Android开发中如何执行POST请求
- [Android开发常见问题-4] RunTime.exec()如何以root权限执行多条指令?
- 一步步教你为网站开发Android客户端---HttpWatch抓包,HttpClient模拟POST请求,Jsoup解析HTML代码,动态更新ListView
- Android开发使用POST方式向服务器请求和发送数据
- Android开发中更新UI时runOnUIthread(Runnable)与Handler.post(Runnable)的区别及如何选择
- Android开发中使用Volley框架发送请求的get和post方法
- Android开发,post、get请求,线程框架
- PHP如何响应移动端(android or ios)的post请求(使用file_get_contents)
- 【Android】安卓开发之使用Gson和POST请求和服务器通信