首页 > 解决方案 > 如何在android中通过HTTP POST发送二维字符串数组

问题描述

我有一个二维数组-String[][] 票价;
和 1 1-D array-String [] 停止;

我想通过 HTTP POST 连接发送它们。下面是我的代码。如何发送它们?

我有一个二维数组-String[][] 票价;
和 1 1-D array-String [] 停止;

我想通过 HTTP POST 连接发送它们。下面是我的代码。如何发送它们?

我有一个二维数组-String[][] 票价;
和 1 1-D array-String [] 停止;

我想通过 HTTP POST 连接发送它们。下面是我的代码。如何发送它们?

代码:
主要:

HTTPConnection1 conn = new HTTPConnection1();
                            conn.execute(stackServer);

功能:

class HTTPConnection1  extends AsyncTask<String, Void, String> {
        String result;
        String url;
        @Override
        protected String doInBackground(String... params) {
            url = params[0];
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(url);
            try {
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair("id", "12345"));
                nameValuePairs.add(new BasicNameValuePair("message", "msg"));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse httpResponse = httpclient.execute(httppost);
                InputStream inputStream = httpResponse.getEntity().getContent();
                //HTTPResult.setText("result3");
                InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
                //HTTPResult.setText("result4");
                BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
                //HTTPResult.setText("result5");
                StringBuilder stringBuilder = new StringBuilder();
                //HTTPResult.setText("result6");
                String bufferedStrChunk = null;

                while((bufferedStrChunk = bufferedReader.readLine()) != null){
                    stringBuilder.append(bufferedStrChunk);
                }


                result = stringBuilder.toString();
                //result= "Sandeep";

            } catch (ClientProtocolException e) {
                result = "ClientProtocolException";
                // TODO Auto-generated catch block
            } catch (IOException e) {
                result = "IOException";
                // TODO Auto-generated catch block
            }
            return null;
        }
        @Override
        protected void onPostExecute(String bitmap) {
            super.onPostExecute(bitmap);
            HTTPResult.setText(result);
        }

标签: androidmultidimensional-arrayhttp-post

解决方案


推荐阅读