Hi I am using DefaultHTTPClient class to create http request.
The currrent code execute() method works on all phones including Nexus and Samsung with Android 6.0.
<
Give something like this a go, i had similar problem on MotoX running 6.0.1 but this seem to work for me.
protected static final int HTTP_JSON_TIMEOUT_CONNECTION = 20000;
protected static final int HTTP_JSON_TIMEOUT_SOCKET = 20000;
CloseableHttpResponse response = null;
try {
UserPrefs.clearCacheFolder(mContext.getCacheDir());
CloseableHttpClient httpClient = getApacheHttpClient();
HttpPost httpPost = getHttpPost( invocation);
response = httpClient.execute(httpPost);
}catch (Exception e){
e.printStackTrace();
}
protected CloseableHttpClient getApacheHttpClient(){
try {
// Socket config
SocketConfig socketConfig = SocketConfig.custom()
.setSoTimeout(HTTP_JSON_TIMEOUT_SOCKET)
.build();
// Auth
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(URL, PORT, null, "Digest"),
new UsernamePasswordCredentials(USERNAME,DIGEST_PASSWORD));
// Build HttpClient
return HttpClients.custom()
.setDefaultSocketConfig(socketConfig)
.setDefaultCredentialsProvider(credentialsProvider)
.build();
}catch (Exception e) {
Log.i("ApacheHttpClientHelper", "ERROR >> "+e.getMessage());
return null;
}
}
Also stick this into the gradle under dependencies
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'