本文主要介绍的是通过http中的GET方式和POST方式上传数据到服务器,其中涉及到解决服务器乱码问题。本文需要服务器和Android前端配合,由于这里是写android方面的问题,后台服务器我就写了一个简单的demo,废话不多说,直接开干。
遵循上一篇的习惯,先来一个布局吧:
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_horizontal"
- android:text="用户名:童义\n密码:123456" />
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="10dp"
- android:orientation="horizontal" >
- <TextView
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:gravity="center_horizontal"
- android:text="用户名:" />
- <EditText
- android:id="@+id/name"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="2"
- android:hint="用户名" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="10dp"
- android:orientation="horizontal" >
- <TextView
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight