Category Archives: androidhttpclient

Compiling Google Download Library targing API 23 Android Marshmallow

I'm using Google's Download library for expansion pack downloading as distributed through the 'Android SDK' manager. Building using Eclipse/Ant since haven't migrated to AS/Gradle yet - but any solution would help.

In API 23 Apache HTTP goes away. And I already implemented a workaround to get Google's LVL to compile. (Lvl library and android marshmallow)

But the download library is substantially larger beast to tackle and not sure I really want to fix Google's code - probably just write my own instead if necessary.

Does anyone know of a convenient "drop in" (-ish) replacement library or suitable workaround?

~~

Compile errors for unavailable imports in 'com.google.android.vending.expansion.downloader.impl.AndroidHttpClient'

import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpEntityEnclosingRequest; import org.apache.http.HttpException; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.ResponseHandler; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.params.HttpClientParams; import org.apache.http.client.protocol.ClientContext; import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.scheme.SocketFactory; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.entity.AbstractHttpEntity; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.RequestWrapper; import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; import org.apache.http.params.HttpProtocolParams; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.BasicHttpProcessor; import org.apache.http.protocol.HttpContext;

Using Apache HttpClient 4.3 with Android and other platforms

I'm currently porting a backup client called Degoo from Windows to Android. The client is written in Java 7 and we're targeting Android 4.4 and above so I figured that most code, except the UI would be pretty straightforward to port. Unfortunately I noticed that Google has decided to force everyone to use a pre-beta version of Apache HttpClient 4.0 (https://hc.apache.org/httpcomponents-client-4.3.x/android-port.html). The problem is that we already use HttpClient 4.3 and need to keep it that way. It would have been fairly straightforward if we'd only have to target Android. Then we'd just use httpclient-android instead. However, now the code must still work with other platforms. We also have some dependencies that have httpclient as a transitive dependency (e.g. httpmime).

What is the most elegant solution to this problem? Should we grab the entire source code of httpclient, change the namespace and have all code use that instead? Then we'd have to do the same thing with all our dependencies that depend on httpclient but so far I haven't come up with any better solution.

HttpClient find an unnamed input field

I'm using Apache HttpClient. I've recently used NameValuePairs in order to fill out forms and submit, but is there a way to fill an input field if it doesn't have a name? I'm attempting to find and fill this input field:

    <span class="sg-combobox-wrapper" id="combobox_plnMain_ddlReportCardRuns"><input class="ui-state-default ui-widget ui-widget-content ui-corner-left ui-autocomplete-input" title="5" value="5" autocomplete="off" style="width: 150px;"><span role="status" aria-live="polite" class="ui-helper-hidden-accessible">7 results are available, use up and down arrow keys to navigate.</span><a tabindex="-1" title="Show All Items" class="ui-button ui-widget ui-state-default ui-button-icon-only ui-corner-right ui-combobox-toggle" role="button" aria-disabled="false"><span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-s"></span><span class="ui-button-text"></span></a></span>

If anyone knows a feasible solution, i'd really appreciate it.

Trying to send HTTP Client image and string to API – compile error = multipartentitybuilder() is not public cannot be accessed from outside package

Since the code below has deprecated classes I've tried all day to find .jars to import that have Apache HttpClient MultipartEntityBuilder class that will import and compile. Below is the old code given to me by the API developer, but it has deprecated classes.

// Image + Multipart
    File image = new File(imageFilename);
    ContentBody body =
            new FileBody(image, "image/jpeg", "image_file", null);
    MultipartEntity multipartContent = new MultipartEntity();
    multipartContent.addPart("image_file", body);

Here is what I've been trying:

        // Image + Multipart
    File image = new File(imageFilename);
    ContentBody body =
            new FileBody(image, "image/jpeg", "image_file", null);
    MultipartEntityBuilder multipartContent = new MultipartEntityBuilder();
    multipartContent.addPart("image_file", body);

build.gradle looks like this:

dependencies {
compile files('libs/moodstocks.jar')
compile files('org.apache.commons.httpclient.jar')
compile files('libs/httpcore-4.0.1.jar')
compile files('libs/httpcore-4.0.1-sources.jar')
compile files('libs/httpclient-4.0.1-sources.jar')
compile files('libs/httpclient-4.3.5.jar')
compile files('libs/httpmime-4.3.6.jar')
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'

}

You can see that I've put a lot of .jars in my libs folder trying to find something that would play nice. I'm essentially just trying to send an image file with a string to an API using Digest Authentication.

I've struggled with this at various times for quite awhile and now that I have most other pieces working I need to figure this communication out.

org.apache.http.NoHttpResponseException: The target server failed to respond in android

Recently move all data to new server, after am got this exception org.apache.http.NoHttpResponseException: The target server failed to respond in all JSON links but its working perfectly in browsers.In old server its was worked well.am not able to solve this.can any one know please help me to solve this issue.

Coding

HttpClient client;
HttpResponse response;
HttpPost post;
InputStream in;
StringEntity se;
int resp_code;

client = new DefaultHttpClient();
post = new HttpPost(getString(R.string.base_url)+ "getCityList");
response = client.execute(post);
resp_code = response.getStatusLine().getStatusCode();
InputStream in = response.getEntity().getContent();
String a = json_res_class.convertStreamToString(in);