2

我有一个问题,我在 Android 设备和某个站点上有应用程序,在按钮上处理 POST 检查的位置,所以我通过在服务器上传递此 POST 检查向该站点发送 POST 请求,并提供正确的数据,并且无法以图表方式单击-side,我需要用我的应用程序或服务器端代码做什么?

这是我发送 POST 的代码:

/****** SEND POST REQUEST ******/
private void sendPostRequest_cabinet(String clientID) 
{
    class SendPostReqAsyncTask extends AsyncTask<String, Void, String> 
    {

        @Override
        protected String doInBackground(String... params) 
        {

            // insert data into massive
            String paramClientID = params[0];

            HttpClient httpClient = new DefaultHttpClient();
            //httpPost = new HttpPost(post_url + /*language from dropdown + */ "/en/login/");


            if (LANGUAGE != null)
            {           
                if (LANGUAGE.equals("English"))
                {
                    httpPost = new HttpPost(link.getEng());
                    Toast.makeText(getApplicationContext(), (CharSequence) httpPost, Toast.LENGTH_LONG).show();
                }
                else if (LANGUAGE.equals("Russian"))
                {
                    httpPost = new HttpPost(link.getRussian());
                }
                else if (LANGUAGE.equals("Dutch(German)"))
                {
                    httpPost = new HttpPost(link.getDeutch());
                }
                else if (LANGUAGE.equals("French"))
                {
                    httpPost = new HttpPost(link.getFrance());
                }
                else if (LANGUAGE.equals("Italian"))
                {
                    httpPost = new HttpPost(link.getItalian());
                }
                else if (LANGUAGE.equals("Spanish"))
                {
                    httpPost = new HttpPost(link.getSpanish());
                }
            }

            // send parameters with values
            BasicNameValuePair email1BasicNameValuePair = new BasicNameValuePair("client_id", paramClientID);

            // insert parameters into massive
            List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
            nameValuePairList.add(email1BasicNameValuePair);

            try 
            {
                UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(nameValuePairList);
                httpPost.setEntity(urlEncodedFormEntity);

                try 
                {
                    HttpResponse httpResponse = httpClient.execute(httpPost);
                    InputStream inputStream = httpResponse.getEntity().getContent();
                    InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
                    BufferedReader buffereReader = new BufferedReader(inputStreamReader);
                    StringBuilder stringBuilder = new StringBuilder();

                    String bufferedStrChunk = null;

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

                    return stringBuilder.toString();
                }
                catch (ClientProtocolException cpe) 
                {
                    System.out.println("First Exception of HttpResponse: " + cpe);
                    cpe.printStackTrace();
                } 
                catch (IOException ioe) 
                {
                    System.out.println("Second Exception of HttpResponse: " + ioe);
                    ioe.printStackTrace();
                }
            } 
            catch (UnsupportedEncodingException uee) 
            {
                System.out.println("An Exception given  because of UrlEncodedFormEntity argument : " + uee);
                uee.printStackTrace();
            }

            return null;
        }

        @Override
        protected void onPostExecute(String result)
        {
            // Toast.makeText(getApplicationContext(),
            // "POST request has been send successfully",
            // Toast.LENGTH_LONG).show();

            super.onPostExecute(result);

            //Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG).show();

            //go to the browser with lang redirect              
            if (LANGUAGE != null)
            {           
                if (LANGUAGE.equals("English"))
                {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(link.getEng()));
                    startActivity(i);
                }
                else if (LANGUAGE.equals("Russian"))
                {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(link.getRussian()));
                    startActivity(i);
                }
                else if (LANGUAGE.equals("Dutch(German)"))
                {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(link.getDeutch()));
                    startActivity(i);
                }
                else if (LANGUAGE.equals("French"))
                {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(link.getFrance()));
                    startActivity(i);
                }
                else if (LANGUAGE.equals("Italian"))
                {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(link.getItalian()));
                    startActivity(i);
                }
                else if (LANGUAGE.equals("Spanish"))
                {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(link.getSpanish()));
                    startActivity(i);
                }
            }
        }
    }
    /***** second check of Internet connection *****/
    if (!isOnline()) 
    {
        showNoConnectionDialog(this);
        // Toast.makeText(getApplicationContext(),
        // "Internet connection is disabled!", Toast.LENGTH_LONG).show();
    } 
    else 
    {
        SendPostReqAsyncTask sendPostReqAsyncTask = new SendPostReqAsyncTask();
        sendPostReqAsyncTask.execute(clientID);
    }
}

UPD 这里是我发送数据和从以前的活动中获取数据的方式:

//go to the ThirdScreen
Intent intent = new Intent(SecondScreen.this, ThirdScreen.class);
intent.putExtra("CLIENT_ID", stringClientID);
intent.putExtra("PASSWORD", getUserPWD);
intent.putExtra("LANGUAGE", language);
startActivity(intent);
finish();

Intent intent = getIntent();
CLIENT_ID = intent.getExtras().getString("CLIENT_ID");

UPD2 也许我没有清楚地解释我需要什么,所以我会尝试解释......我有网站,我需要通过 POST 向这个网站发送一些数据,这是什么意思?我启动我的 Android 应用程序,用数据填写一些文本框,然后单击按钮,通过单击此按钮,我需要打开 WebBrowser 并将数据发送到该站点...

4

1 回答 1

0

我通过在其中创建带有 WebView 组件的新活动并检索需要的站点来确定我的问题,因此版主可以关闭此问题。

于 2013-03-13T23:07:51.343 回答