我们如何在android studio 6.0版中加入“HttpParam”

时间:2016-02-16 17:23:43

标签: android android-studio

我正在使用android studio 1.5.1 API 23,当我们在java程序中使用“HttpParams”时,我们得到了一些错误,就像我们不能在这个版本中使用它所以我怎么能把它包含在我的android工作室中?

    @Override
    protected Void doInBackground(Void... params) {
        ArrayList<NameValuePair> dataToSend = new ArrayList<>();
        dataToSend.add(new BasicNameValuePair("username", user.username));
        dataToSend.add(new BasicNameValuePair("name", user.name));
        dataToSend.add(new BasicNameValuePair("contect", user.contect));
        dataToSend.add(new BasicNameValuePair("BloodGroup", user.bloodgroup));
        dataToSend.add(new BasicNameValuePair("password", user.password));



        /*URL url = new URL(SERVER_ADDRESS +"Register.php");
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet();
        request.setURI(new URI(link));*/
        //HttpParams httpParams = new BasicHttpParams();
        HttpParams httpRequestParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpRequestParams, CONNECTION_TIMEOUT);


        HttpClient client = new DefaultHttpClient(httpRequestParams);
        HttpPost post = new HttpPost(SERVER_ADDRESS +"Register.php");

       try{
            post.setEntity(new UrlEncodedFormEntity(dataToSend));
           client.execute(post);
        }catch (Exception e){
            e.printStackTrace();

        }


        return null;
    }

1 个答案:

答案 0 :(得分:1)

API level 23 removed support for the Apache HTTP client

如果您确实需要使用Apache HTTP类,可以通过在build.gradle中包含它来实现:

android {
    useLibrary 'org.apache.http.legacy'
}

但是,您应该只作为最后的手段。相反,您应该查看从Apache HTTP客户端迁移的选项。