我的android工作室有问题。当我想将它们发送到服务器时,我的android中有很多变量(76个变量)我有问题。它无法将数据发送到我的服务器。但是当我尝试减少变量变成2变量时它起作用。可以解释一下吗?
private void orderproses(String merk,String tipe,String tipe_mesin,String transmisi,String warnaint,String warnaext,String pernahlaka,String lamakepemilikan,String silinder,String kondisibeli,String kondisiumum,
String fiturmobil,String speedometer,String ukuran,String harga,String penjual,String nohp,String s1,String s2,String s3,String s4,String s5,String s6,String s7,String s8,String s9,String s10,String s11,String s12,String s13,String s14,String s15,String s16,String s17,String s18,
String o1,String o2,String o3,String o4,String o5,String o6,String o7,String o8,String o9,String o10,String o11,String o12,String o13,String o14,String o15,
String Setelah1,String Setelah2, String Setelah3, String Setelah4, String Setelah5, String Setelah6, String Setelah7, String Setelah8, String Setelah9,
String no1,String no2,String no3,String no4ya,String no5ya,String no6gadai,String no7,String no8,
String no4,String no5,String no6,String jb1,String jb2,String jb3,String jb4,String id,String mail) {
class RegisterUser extends AsyncTask<String, Void, String> {
ProgressDialog loading;
RegisterUserClass ruc = new RegisterUserClass();
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(CatatanPenutupActivity.this, "Please Wait",null, true, true);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
Toast.makeText(getApplicationContext(), s, Toast.LENGTH_LONG).show();
//session.logoutUser();
Intent i = new Intent(CatatanPenutupActivity.this, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
}
@Override
protected String doInBackground(String... params) {
HashMap<String, String> data = new HashMap<String,String>();
data.put("1",params[0]);
data.put("2",params[1]);
data.put("3",params[2]);
data.put("4",params[3]);
data.put("5",params[4]);
data.put("6",params[5]);
data.put("7",params[6]);
data.put("8",params[7]);
data.put("9",params[8]);
data.put("10",params[9]);
data.put("11",params[10]);
data.put("12",params[11]);
data.put("13",params[12]);
data.put("14",params[13]);
data.put("15",params[14]);
data.put("16",params[15]);
data.put("17",params[16]);
data.put("18",params[17]);
data.put("19",params[18]);
data.put("20",params[19]);
data.put("21",params[20]);
data.put("22",params[21]);
data.put("23",params[22]);
data.put("24",params[23]);
data.put("25",params[24]);
data.put("26",params[25]);
data.put("27",params[26]);
data.put("28",params[27]);
data.put("29",params[28]);
data.put("30",params[29]);
data.put("31",params[30]);
data.put("32",params[31]);
data.put("33",params[32]);
data.put("34",params[33]);
data.put("35",params[34]);
data.put("36",params[35]);
data.put("37",params[36]);
data.put("38",params[37]);
data.put("39",params[38]);
data.put("40",params[39]);
data.put("41",params[40]);
data.put("42",params[41]);
data.put("43",params[42]);
data.put("44",params[43]);
data.put("45",params[44]);
data.put("46",params[45]);
data.put("47",params[46]);
data.put("48",params[47]);
data.put("49",params[48]);
data.put("50",params[49]);
data.put("51",params[50]);
data.put("52",params[51]);
data.put("53",params[52]);
data.put("54",params[53]);
data.put("55",params[54]);
data.put("56",params[55]);
data.put("57",params[56]);
data.put("58",params[57]);
data.put("59",params[58]);
data.put("60",params[59]);
data.put("61",params[60]);
data.put("62",params[61]);
data.put("63",params[62]);
data.put("64",params[63]);
data.put("65",params[64]);
data.put("66",params[65]);
data.put("67",params[66]);
data.put("68",params[67]);
data.put("69",params[68]);
data.put("70",params[69]);
data.put("71",params[70]);
data.put("72",params[71]);
data.put("73",params[72]);
data.put("id",params[73]);
data.put("mail",params[74]);
String result = ruc.sendPostRequest(REGISTER_URL2,data);
return result;
}
}
RegisterUser ru = new RegisterUser();
ru.execute(merk,tipe,tipe_mesin,transmisi,warnaint,warnaext,pernahlaka,lamakepemilikan,silinder,kondisibeli,kondisiumum,
fiturmobil,speedometer,ukuran,harga,penjual,nohp,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s18,
o1,o2,o3,o4,o5,o6,o7,o8,o9,o10,o11,o12,o13,o14,o15,
Setelah1, Setelah2, Setelah3, Setelah4, Setelah5, Setelah6, Setelah7, Setelah8, Setelah9,
no1,no2,no3,no4ya,no5ya,no6gadai,no7,no8,
no4,no5,no6,jb1,jb2,jb3,jb4,id,mail);
}
`
答案 0 :(得分:0)
public class RegisterUserClass {
public String sendPostRequest(String requestURL,
HashMap<String, String> postDataParams) {
URL url;
String response = "";
try {
url = new URL(requestURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(1500000);
conn.setConnectTimeout(1500000);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(getPostDataString(postDataParams));
writer.flush();
writer.close();
os.close();
int responseCode=conn.getResponseCode();
if (responseCode == HttpsURLConnection.HTTP_OK) {
BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream()));
response = br.readLine();
}
else {
response="Error Registering";
}
} catch (Exception e) {
e.printStackTrace();
}
return response;
}
private String getPostDataString(HashMap<String, String> params) throws UnsupportedEncodingException {
StringBuilder result = new StringBuilder();
boolean first = true;
for(Map.Entry<String, String> entry : params.entrySet()){
if (first)
first = false;
else
result.append("&");
result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
}
return result.toString();
}
}