I have been using the build-in android httpclient and Springs Android Resttemplate (1.0.0.M4) in my Android app. I'm authenticating with Basic Auth.
I have a couple of things i need to set when making requests, most importantly credentials charset. Default is US-Ascii and nordic characters doesn't work unless i set it to ISO-8859.
I did that using the HttpClient:
HttpClient httpClient = new HttpClient();
Credentials defaultcreds = new UsernamePasswordCredentials(msisdn, password);
httpClient.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), defaultcreds);
httpClient.getParams().setSoTimeout(prefs.getServerTimeout());
httpClient.getParams().setConnectionManagerTimeout(3000);
httpClient.getParams().setContentCharset("UTF-8");
httpClient.getParams().setCredentialCharset("ISO-8859-1", )
I'm now trying to upgrade my libraries, and also get rid of the built-in httpclient dependency.
SO, i'm upgrading to resttemplate 2.0, and have imported apache's httpclient-android. I'm using Maven, so my dependencies are:
<dependency>
<groupId>org.springframework.android</groupId>
<artifactId>spring-android-rest-template</artifactId>
<version>2.0.0.M3</version>
<!--version>1.0.0.M4</version-->
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient-android</artifactId>
<version>4.3.5.1</version>
</dependency>
I have a hard time making this work as i want...
Neither of the jars above have a HttpClient class anywhere. Since the Android one is deprecated, i don't want to rely on that one.
According to the docs, Basic Auth should be performed as per the below code. But i cannot find anywhere to set the credentials charset!
HttpAuthentication authHeader = new HttpBasicAuthentication(msisdn, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); HttpEntity requestEntity = new HttpEntity(requestHeaders);
It would be great if someone could help me out.
cz.msebera.android:httpclient:4.4.1.1hascz.msebera.android.httpclient.client.HttpClient. That's what I used in this book sample and this NetCipher code. With regards to basic auth charsets, I have no idea.