美好的一天, 我有一个PHP代码,有一个$ _POST ['查询']功能,我想用$ _POST ['标签']添加它但是如何在android中传递2个变量对于PHP,我已经用我的代码将一个值传递给了$ _POST ['查询']但是如何通过第二个呢?
OutputStream os = con.getOutputStream();
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
String data = URLEncoder.encode("Query", "UTF-8")+"="+URLEncoder.encode(query,"UTF-8");
bw.write(data);
bw.flush();
con.connect();
bw.close();
os.close();
答案 0 :(得分:1)
只需在&
String data = URLEncoder.encode("Query", "UTF-8")+"="+URLEncoder.encode(query,"UTF-8");
data+= "&"+URLEncoder.encode("Tags", "UTF-8")+"="+URLEncoder.encode(yourTags,"UTF-8");
注意:为提高效率StringBuilder
StringBuilder params = new StringBuilder();
params.append(URLEncoder.encode("Query", "UTF-8")+"="+URLEncoder.encode(query,"UTF-8"));
params.append("&");
params.append(URLEncoder.encode("Tags", "UTF-8")+"="+URLEncoder.encode(yourTagStr,"UTF-8"));
bw.write(params.toString());
// ... code