相关疑难解决方法(0)

如何将Apache HTTP API(旧版)作为编译时依赖添加到Android M的build.grade?

如前所述这里,Android的M将不支持的Apache HTTP API.文档声明:

请改用HttpURLConnection类.

要么

要继续使用Apache HTTP API,必须首先在build.gradle文件中声明以下编译时依赖项:

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

我已经将我项目的大部分HttpClient用法转换为HttpURLConnection,但是,我仍然需要在一些领域使用HttpClient.因此,我试图将'org.apache.http.legacy'声明为编译时依赖项,但在build.gradle中出现错误:

找不到Gradle DSL方法:'useLibrary()'

我的问题是:如何在项目中将'org.apache.http.legacy'声明为编译时依赖项?

任何帮助深表感谢.谢谢

apache android httpclient build.gradle android-6.0-marshmallow

94
推荐指数
5
解决办法
10万
查看次数

不推荐使用MultipartEntity类型

文档说org.apache.http.entity.mime.MultipartEntity 该类已被弃用.有人可以建议我另类吗?

我在我的代码中使用这个:

entity.addPart("params", new StringBody("{\"auth\":{\"key\":\""
            + authKey + "\"},\"template_id\":\"" + templateId + "\"}"));
entity.addPart("my_file", new FileBody(image));
httppost.setEntity(entity);
Run Code Online (Sandbox Code Playgroud)

java apache

43
推荐指数
2
解决办法
5万
查看次数

如何在没有HttpEntity的情况下使用Volley发送多部分请求?

我正在按照解决方案使用Android VolleyHow to multipart数据中使用 volley发送多部分请求.但是,自SDK 22以来,httpsntity已被弃用,并且已在SDK 23上完全删除.

解决方案是使用openConnection,就像现在在Android上弃用HttpEntity一样,有什么替代方案?,但我不知道如何将它用于多部分请求

android android-volley httpentity

5
推荐指数
1
解决办法
5268
查看次数

如何从HttpClient切换到HttpUrlConnection?

我正在创建一个Android应用程序,我通过HttpClient将数据从Android应用程序发送到servlet.我使用HttpPost方法.

我在Android开发者网站上读到Apache HttpClient库在Android Froyo 2.2中有一些错误,毕竟使用HttpUrlConnection而不是HttpPost是一个好习惯.所以我想将我的HttpPost代码转换为HttpUrlConnectio,但不知道如何.

我在这里发布我的Android代码以及servlet代码

Android代码

private String postData(String valueIWantToSend[]) 
    {
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url);
        try 
        {
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("param1",valueIWantToSend[0]));
            nameValuePairs.add(new BasicNameValuePair("param2", valueIWantToSend[1]));
            nameValuePairs.add(new BasicNameValuePair("param3", valueIWantToSend[2]));
            nameValuePairs.add(new BasicNameValuePair("param4", valueIWantToSend[3]));
            nameValuePairs.add(new BasicNameValuePair("param5", valueIWantToSend[4]));
            nameValuePairs.add(new BasicNameValuePair("param6", valueIWantToSend[5]));
            nameValuePairs.add(new BasicNameValuePair("param7", valueIWantToSend[6]));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            /* execute */
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity rp = response.getEntity();

            //origresponseText=readContent(response);
        }
        catch (ClientProtocolException e) 
        {
            // TODO Auto-generated catch …
Run Code Online (Sandbox Code Playgroud)

java android servlets httpurlconnection apache-httpclient-4.x

4
推荐指数
2
解决办法
1万
查看次数

无法解析符号HttpEntity,HttpResponse

我正在尝试使用教程学习XML解析,但有些类没有导入.这是代码:

public String getXmlFromUrl(String url) {
    String xml = null;

    try {
        // defaultHttpClient
        DefaultHttpClient client = new DefaultHttpClient();
        HttpResponse resp = client.execute(uri);

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        xml = EntityUtils.toString(httpEntity);

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // return XML
    return xml;
}
Run Code Online (Sandbox Code Playgroud)

这些类没有导入:

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.impl.client.DefaultHttpClient;
Run Code Online (Sandbox Code Playgroud)

我的Gradle属性:

android {
    compileSdkVersion 23
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId …
Run Code Online (Sandbox Code Playgroud)

android xml-parsing androidhttpclient

4
推荐指数
1
解决办法
2万
查看次数

3
推荐指数
1
解决办法
8825
查看次数

来自androidhive教程的JSONParser,DefaultHttpClient中的NoSuchMethodError

我正在关注教程,并收到此错误:

Caused by: java.lang.NoSuchMethodError: No virtual method execute(Lorg/apache/http/client/methods/HttpUriRequest;)Lorg/apache/http/client/methods/CloseableHttpResponse; in class Lorg/apache/http/impl/client/DefaultHttpClient; or its super classes (declaration of 'org.apache.http.impl.client.DefaultHttpClient' appears in /system/framework/ext.jar)
                at info.androidhive.materialtabs.adpater.JSONParser.makeHttpRequest(JSONParser.java:52)
                at info.androidhive.materialtabs.UserFunctions.loginUser(UserFunctions.java:37)
                at info.androidhive.materialtabs.activity.MainActivity$Login.doInBackground(MainActivity.java:551)
                at info.androidhive.materialtabs.activity.MainActivity$Login.doInBackground(MainActivity.java:519)
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的JSONParser类:

public class JSONParser {
     static InputStream is = null;
        static JSONObject jObj = null;
        static String json = "";
        // constructor
        public JSONParser() {
        }
        // function get json from url
        // by making HTTP POST or GET method
        public JSONObject makeHttpRequest(String url, String method,
                List<NameValuePair> params) { …
Run Code Online (Sandbox Code Playgroud)

java android

2
推荐指数
1
解决办法
4928
查看次数

为什么AsyncTask会使用弃用的行?在我的代码?

我正在做一个AsyncTask,如果我将sdk降低到22,我可以添加.

在sdk 23上它根本不起作用,即使在22年,它也为我写了一些内容.

我究竟做错了什么 ?或者如何纠正它以便我可以在sdk 23运行它?

@Override
    protected Boolean doInBackground(String... urls) {

        try {

            //------------------>>
            HttpGet httppost = new HttpGet(urls[0]);
            HttpClient httpclient = new DefaultHttpClient();
            HttpResponse response = httpclient.execute(httppost);

            // StatusLine stat = response.getStatusLine();
            int status = response.getStatusLine().getStatusCode();

            if (status == 200) {
                HttpEntity entity = response.getEntity();
                String data = EntityUtils.toString(entity);

                JSONObject jsono = new JSONObject(data);

                //this gets us the actors node and puts it in jarray veriable
                JSONArray jarray = jsono.getJSONArray("actors");

                for (int i = 0; i < jarray.length(); …
Run Code Online (Sandbox Code Playgroud)

android android-asynctask

-1
推荐指数
1
解决办法
1091
查看次数