2013-03-12 504 views
2

我有一個問題,我有Android設備和一些網站上的應用程序,POST按鈕在按鈕上處理,所以我發送POST請求到這個網站,有正確的數據,並且可以用圖解方式點擊,通過在服務器端傳遞這個POST檢查,我需要用我的應用程序或服務器端代碼來做什麼?Android:點擊網站上的按鈕

這裏是我的代碼,我發送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並將數據發送到此網站...

回答

0

我決定通過創建新活動其中包含WebView組件,並檢索需要的網站,因此版主可以關閉此問題。