Android应用中的cURL命令

时间:2016-10-30 12:52:51

标签: android json curl

我想在我的android应用程序中运行cURL命令,但我不知道如何。 这是示例命令:

curl --data "mail=abc@abc.com&pass=azerty" http://www.website.com/login/

2 个答案:

答案 0 :(得分:0)

你可以使用android NDK实现这一点,here是一个很好的文章来实现这个任务

答案 1 :(得分: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","abc@abc.tn"));
                    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();