安卓:如何发送可变参数与GetHttp? [英] Android: How to send variable parameters with GetHttp?

查看:157
本文介绍了安卓:如何发送可变参数与GetHttp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android的新的和我堵住一个问题,我不知道如何解决:
从我的应用程序我试图以修改服务器上的XML文件发送这种形式的信息到服务器:

I'm new in Android and I am blocked with a problem I don't know how to solve: from my app I'm trying to send a message of this form to a server in order to modify a xml file on the server:

https://myserver/index.php?x0=param1&y0=param2&z0=param3    

我设法使之与使用code参数1,参数2和参数3,即固定值以下工作我修改服务器上的XML文件的值设置为1,2和3:

I managed to make it work with fixed values of param1, param2 and param3, i.e. using the code below I modify the values of the xml file on the server to 1, 2 and 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 ...

But my problem is that I want to send not fixed values, but the values (variables) which are input by the user and are read in the "InitialPosListener" : x00, y00 and z00...

有没有办法做到这一点?非常感谢

Is there a way to do this? Thanks a lot

推荐答案

看起来你只是在执行HTTP GET到服务器。呼叫

It looks like you are just executing HTTP GET to your server. Calling

new RequestTask().execute("https://myserver/index.php?x0=" + x00 + "&y0=" + y00 + "&z0=" + z00);

会做你想做的。

这篇关于安卓:如何发送可变参数与GetHttp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆