我是 Android 新手,遇到了一个我不知道如何解决的问题:我正在尝试从我的应用程序向服务器发送此表单的消息,以便修改服务器上的 xml 文件:
https://myserver/index.php?x0=param1&y0=param2&z0=param3
我设法使它与 param1、param2 和 param3 的固定值一起工作,即使用下面的代码我将服务器上的 xml 文件的值修改为 1、2 和 3:
private OnClickListener InitialPosListener = new OnClickListener() {
@Override
public void onClick(View v) {
String x00 = InitialPosX.getText().toString(); String y00 = InitialPosY.getText().toString(); String z00 = InitialPosZ.getText().toString();
float x0 = Float.valueOf(x00); float y0 = Float.valueOf(y00); float z0 = Float.valueOf(z00);
new RequestTask().execute(https://myserver/index.php?x0=1&y0=2&z0=3);
}
};
class RequestTask extends AsyncTask<String, String, String>{
@Override
protected String doInBackground(String... uri) {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
String responseString = null;
try {
response = httpclient.execute(new HttpGet(uri[0]));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
responseString = out.toString();
} else{
//Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (ClientProtocolException e) {
//TODO Handle problems..
} catch (IOException e) {
//TODO Handle problems..
}
return responseString;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
//Do anything with response..
}
}
但我的问题是我想发送的不是固定值,而是用户输入并在“InitialPosListener”中读取的值(变量):x00、y00 和 z00...
有没有办法做到这一点?非常感谢