2016-10-30 31 views
-1

我想運行一個cURL命令到我的android應用程序,但我不知道如何。 這是示例命令:在Android應用程序的cURL命令

curl --data "[email protected]&pass=azerty" http://www.website.com/login/ 
+2

你正在尋找一個HTTP客戶端。 – SLaks

+0

我不知道如何用CURL調用 –

+0

這可能是http://stackoverflow.com/questions/20782140/convert-curl-command-into-java-android –

回答

0

可以實現這一目標使用的Android NDK,here是一個很好的文章,以實現這一目標任務

+0

感謝您的幫助,但我發現這個解決方案非常複雜 –

0

謝謝大家,我發現這個解決方案:

new Thread(new Runnable() { 

      @Override 
      public void run() { 
       final HttpParams params = new BasicHttpParams(); 
       HttpClientParams.setRedirecting(params, true); 
       HttpClient httpclient = new DefaultHttpClient(); 

       HttpPost httppost = new HttpPost(
         "http://wwwebsite.com/login/"); 
       String HTML = ""; 
       try { 
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
          3); 
        nameValuePairs.add(new BasicNameValuePair("mail","[email protected]")); 
        nameValuePairs.add(new BasicNameValuePair("pass", "azerty")); 
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

        HttpResponse response = httpclient.execute(httppost); 

        HTML = EntityUtils.toString(response.getEntity()); 
        if (response.getEntity() != null) { 
         Log.i("RESPONSE", HTML.toString()); 
        } 

       } catch (ClientProtocolException e) { 
        Log.e("ee","ee"); 
       } catch (IOException e) { 
        Log.e("ee","ee"); 

       } 

      } 
     }).start();