数据转换工具类:
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
/**
* Created by Administrator on 2018/9/14 0014.
*/
public class Util_app {
public String DATA_URLEncoder(String data_name[],String[] data_value){
String return_value = "";
//声明返回值
//判断 键值长度是否相等
if(data_name.length==data_value.length){
//循环赋值
for(int i=0;i<data_name.length;i++){
try {
//做数据格式转换,UTF-8 中文格式
return_value+=URLEncoder.encode(data_name[i], "UTF-8") + "=" +URLEncoder.encode(data_value[i], "UTF-8");
//非末尾使用 & 拼接
if(i!=data_name.length-1){return_value+="&";}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}else{
return_value = "data_erro";
}
return return_value;
}
}
请求链接管理类
public class Data {
static String home_url = "http://你的域名";
static String login_url = home_url+"/mz_pbl/app_con/login_up.php";
}
网络请求处理层(一般不用修改)
package com.example.administrator.myapplication;
import android.util.Log;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
/**
* Created by Administrator on 2018/9/14 001