android,HttpPost发送数据到服务器
来源:互联网 发布:淘宝联盟批量链接工具 编辑:程序博客网 时间:2024/06/05 15:44
/** * 采用httpclient post数据到服务器 */public void loginByClientPost() {String password = et_password.getText().toString().trim();String name = et_username.getText().toString().trim();if (TextUtils.isEmpty(name) || TextUtils.isEmpty(password)) {Toast.makeText(this, "用户名密码不能为空", 1).show();return;}try {// 1.创建一个浏览器HttpClient client = new DefaultHttpClient();// 2.准备一个连接HttpPost post = new HttpPost("http://192.168.1.100:8080/web/LoginServlet");// 要向服务器提交的数据实体List<NameValuePair> parameters = new ArrayList<NameValuePair>();parameters.add(new BasicNameValuePair("name", name));parameters.add(new BasicNameValuePair("password", password));UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters,"utf-8");post.setEntity(entity);// 3.敲回车HttpResponse response = client.execute(post);int code = response.getStatusLine().getStatusCode();if (code == 200) {InputStream is = response.getEntity().getContent();String result = StreamTools.readFromStream(is);Toast.makeText(this, result, 1).show();} else {Toast.makeText(this, "服务器异常", 1).show();}} catch (Exception e) {e.printStackTrace();Toast.makeText(this, "client post 失败", 1).show();}}
学会这个。就可以快速的访问某个需要传参数的网址了。参数名字,要用浏览器抓包工具,看数据包就可以晓得了。可以做些抢票,秒杀工具等。
0 0
- android,HttpPost发送数据到服务器
- Android HTTPpost 提交数据到服务器
- Android使用HttpPost向服务器发送Json数据
- Android使用HttpPost向服务器发送Json数据
- Android使用HttpPost向服务器发送Json数据
- zz:Android使用HttpPost向服务器发送Json数据
- Android使用HttpPost向服务器发送Json数据
- android通过httpPost向服务器发送请求
- android通过httpPost向服务器发送请求 .
- android通过httpPost向服务器发送请求
- Android之使用HttpPost提交数据到服务器(Android手机客户端和后台服务器交互)
- Android开发中HTTP协议HttpPost向服务器发送JSon数据格式的数据
- android,post发送数据到服务器
- android, httpclient,get,发送数据到服务器
- Android利用JSON发送数据到服务器
- Android利用JSON发送数据到服务器
- Android利用JSON发送数据到服务器
- 发送数据到服务器
- NOSQL----Redis(1)
- SetUnhandledExceptionFilter函数学习
- hdu 1022 Train Problem I
- 游戏运行时,WIN2003报错:设备 \Device\Harddisk0有一个不正确的区块。
- 泛型技术
- android,HttpPost发送数据到服务器
- 特征变换以及维度下降——LDA VS PCA
- 关于公交系统中运用NFC-TSM技术进行移动支付的解决案例浅析
- 正则表达式(二)
- 详解Cocos2d-X中宏CC_DLL
- hdu 1702 ACboy needs your help again
- Linux vsftp服务的安装
- POJ 1005 I Think I Need a Houseboat
- hdu 2044 (水题)