It does not take a multi-threaded query - java

faced with multi-threading when sending HTTP requests
a feeling that they are still waiting for the completion of each other ..
because the speed of queries is not impressed (compared to C # \ Perl)
For the first time faced with a similar to C #, it turned out that the problem was solved by removing limits on connections
ServicePointManager.DefaultConnectionLimit = 100;
Can someone tell what is wrong in my example?
whether there are such limits in java?
public static String requester(String url, String param, int head, String cook, int ajax) {
HttpClient client = getHttpsClient(new DefaultHttpClient());
HttpPost httppost = new HttpPost(url);
String ans = new String();
if(ajax == 1) {
httppost.setHeader("Content-Type", "application/json;charset=utf-8");
httppost.setHeader("Accept", "application/json");
}
httppost.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36");
if(cook != "") {
httppost.setHeader("Cookie", cook);
}
try {
StringEntity se = new StringEntity(param);
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
httppost.setEntity(se);
HttpResponse response = client.execute(httppost);
if(head == 1) {
ans = TextUtils.join("\r\n", response.getAllHeaders());
}
StringBuilder builder = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
for (String line = null; (line = reader.readLine()) != null;) {
builder.append(line).append("\n");
}
ans += builder.toString();
} catch (ClientProtocolException e) {
Log.d("ClientProtocolException","Some Wrong 1");
} catch (IOException e) {
Log.d("ClientProtocolException", e.getLocalizedMessage());
}
return ans;
}
....
public void brute(View v)
{
flag = 0;
for(int i = 0; i < 100; i++)
{
new TheTask().execute();
}
}
class TheTask extends AsyncTask<Void,Void,Void>
{
#Override
protected Void doInBackground(Void... params) {
while(true)
{
..........
public static HttpClient getHttpsClient(HttpClient client) {
try{
X509TrustManager x509TrustManager = new X509TrustManager() {
#Override
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
#Override
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
#Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
HttpParams params = new BasicHttpParams();
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(100));
ConnManagerParams.setMaxTotalConnections(params, 10000);
HttpConnectionParams.setSocketBufferSize(params,8192);
HttpConnectionParams.setTcpNoDelay(params, true);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
ClientConnectionManager clientConnectionManager = new ThreadSafeClientConnManager(params, registry);
clientConnectionManager.setMaxTotal (1000);
clientConnectionManager.setDefaultMaxPerRoute (100);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[]{x509TrustManager}, null);
SSLSocketFactory sslSocketFactory = new ExSSLSocketFactory(sslContext);
sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
//ClientConnectionManager clientConnectionManager = client.getConnectionManager();
SchemeRegistry schemeRegistry = clientConnectionManager.getSchemeRegistry();
schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
//return new DefaultHttpClient(clientConnectionManager, client.getParams());
return new DefaultHttpClient(clientConnectionManager, params);
} catch (Exception ex) {
return null;
}
}

See: See http://hc.apache.org/httpclient-3.x/performance.html and http://hc.apache.org/httpclient-3.x/threading.html.
I can't tell from your post, but you appear not to be re-using the HttpClient, but you're definitely not giving it a thread safe connection manager. There are other performance considerations you may need, depending on your application (but are detailed in the above links).
Also, from my own personal, anecdotal evidence, HttpClient 4.x is generally faster than HttpClient 3.x (again, it's not clear which you're using).

Solved
ConnPerRoute perRoute = new ConnPerRouteBean(100);
ConnManagerParams.setMaxConnectionsPerRoute(params, perRoute);
ConnManagerParams.setMaxTotalConnections(params, 100);
ConnManagerParams.setTimeout(params, 15000);

Related

"IllegalStateException: Unexpected request state READY" when using HttpAsyncClient under high concurrency

We have a HttpAsyncUtil to process HTTP POST requests.
public class HttpAsyncUtil {
private static CloseableHttpAsyncClient client = null;
static {
try {
// Connect time out: 2s, read time out: 10s, request time out: 5s
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(2000).setSocketTimeout(10000).setConnectionRequestTimeout(5000).build();
IOReactorConfig ioReactorConfig = IOReactorConfig.custom().setIoThreadCount(20).setSoKeepAlive(false).build();
ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(ioReactorConfig);
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
// don't check
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
// don't check
}
}
};
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, null);
SSLIOSessionStrategy sslioSessionStrategy = new SSLIOSessionStrategy(sslContext, SSLIOSessionStrategy.ALLOW_ALL_HOSTNAME_VERIFIER);
Registry<SchemeIOSessionStrategy> registry = RegistryBuilder.<SchemeIOSessionStrategy>create()
.register("http", NoopIOSessionStrategy.INSTANCE)
.register("https", sslioSessionStrategy)
.build();
PoolingNHttpClientConnectionManager connectionManager = new PoolingNHttpClientConnectionManager(ioReactor,registry);
connectionManager.setMaxTotal(2000);
connectionManager.setDefaultMaxPerRoute(2000);
client = HttpAsyncClients.custom().setConnectionManager(connectionManager)
.setDefaultRequestConfig(requestConfig)
.build();
} catch (Exception ex) {
// System.exit(0);
}
}
public static void post(String url, Map<String, String> params, Map<String, String> headers, FutureCallback<HttpResponse> callback) throws Exception {
HttpPost httpPost = new HttpPost(url);
if (headers != null) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
httpPost.setHeader(entry.getKey(), entry.getValue());
}
}
if (params != null) {
List<NameValuePair> parameters = new ArrayList<>(params.size());
for (Map.Entry<String, String> entry : params.entrySet()) {
parameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(parameters, "UTF-8");
httpPost.setEntity(formEntity);
}
client.start();
client.execute(httpPost,callback);
}
It works well under low concurrency. However, something went wrong when processing pressure test.
java.lang.IllegalStateException: Unexpected request state READY
at org.apache.http.util.Asserts.check(Asserts.java:46)
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.outputReady(HttpAsyncRequestExecutor.java:231)
at org.apache.http.impl.nio.DefaultNHttpClientConnection.produceOutput(DefaultNHttpClientConnection.java:290)
at org.apache.http.impl.nio.client.InternalIODispatch.onOutputReady(InternalIODispatch.java:86)
at org.apache.http.impl.nio.client.InternalIODispatch.onOutputReady(InternalIODispatch.java:39)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.outputReady(AbstractIODispatch.java:145)
at org.apache.http.impl.nio.reactor.BaseIOReactor.writable(BaseIOReactor.java:188)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:341)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:588)
at java.base/java.lang.Thread.run(Thread.java:834)
The source code shows that the Connection state is expected to be BODY_STREAM or ACK_EXPECTED but its actually READY. It seems that something special events reset the Connection state. But we cannot find more evidence on this.

404 with youtube-mp3.org api

I'm trying to make an app that can download mp3 files by a youtube url.
I did some research on the youtube-mp3.org api and this is the way I think it should be done:
Get http://www.youtube-mp3.org/api/pushItem/?item=http://www.youtube.com/watch?v=xo9EV3A4oaA&xy=yx
Step 1 returns an ID, which you have to use in the following request: "http://www.youtube-mp3.org/api/itemInfo/?video_id=" + ID
Step 2 returns another code, which you have to use in this request: "http://www.youtube-mp3.org/get?video_id=xo9EV3A4oaA&h=" + <code from step 2>
Step 3 retruns the mp3.
Unfortunately, my code already fails at step 1: I'm getting a 404, page not found.
Here's my code (only for step 1):
private DefaultHttpClient createHttpClient() {
HttpParams my_httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(my_httpParams, 3000);
HttpConnectionParams.setSoTimeout(my_httpParams, 15000);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
ThreadSafeClientConnManager multiThreadedConnectionManager = new ThreadSafeClientConnManager(my_httpParams, registry);
DefaultHttpClient httpclient = new DefaultHttpClient(multiThreadedConnectionManager, my_httpParams);
return httpclient;
}
private class DownloadVid extends AsyncTask<Void, Void, Void> {
int mStatusCode = 0;
String content = "";
#Override
protected Void doInBackground(Void... args) {
String url = "http://www.youtube-mp3.org/api/pushItem/?item=http://www.youtube.com/watch?v=xo9EV3A4oaA&xy=yx";
DefaultHttpClient httpclient = createHttpClient();
HttpGet httpget = new HttpGet(url);
httpget.addHeader("Accept-Location", "*");
try {
HttpResponse response = httpclient.execute(httpget);
StatusLine statusLine = response.getStatusLine();
mStatusCode = statusLine.getStatusCode();
if (mStatusCode == 200){
content = EntityUtils.toString(response.getEntity());
}
} catch (ClientProtocolException e) {
e.printStackTrace();
mStatusCode = 0;
} catch (IOException e) {
e.printStackTrace();
mStatusCode = 0;
} catch (IllegalStateException e){
e.printStackTrace();
mStatusCode = 0;
}
return null;
}
#Override
protected void onPostExecute(Void arg) {
mProgressDialog.dismiss();
Toast.makeText(MainActivity.this, "Result=" + content + " StatusCode=" + mStatusCode, Toast.LENGTH_LONG).show();
}
}
I'm not sure why it isn't working. Any ideas?
Encode the item parameter, like this:
String item = URLEncoder.encode("http://www.youtube.com/watch?v=xo9EV3A4oaA", "utf-8");
String url = "http://www.youtube-mp3.org/a/pushItem/?item="+item+"&xy=yx";
Or like this:
Uri uri = new Uri.Builder()
.scheme("http")
.authority("www.youtube-mp3.org")
.path("/a/pushItem/")
.appendQueryParameter("item", "http://www.youtube.com/watch?v=xo9EV3A4oaA")
.appendQueryParameter("xy", "yx")
.build();

Android: How to create a HttpClient with self signed certificate and a SSL cache

I have some trouble to realize a SSL connection with Android. My program sends data in an specific time interval. To kepp down the sent data volume I want to use a SSL cache.
Does anybody know how to create a HttpClient in Android with a self signed certificate and a SSL cache?
I want to use the HttpClient class and my solution looks like the following (ending in a CastException):
private HttpClient getNewHttpClient(Context context, InputStream sslCertificate) {
SSLSessionCache sslSessionCache = new SSLSessionCache(context);
SSLCertificateSocketFactory socketFactory = (SSLCertificateSocketFactory) SSLCertificateSocketFactory.getDefault(15000, sslSessionCache);
KeyStore keyStore = getSSLKeyStore(sslCertificate);
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
socketFactory.setTrustManagers(tmf.getTrustManagers());
HttpParams connectionParameters = new BasicHttpParams();
HttpProtocolParams.setVersion(connectionParameters , HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(connectionParameters , HTTP.UTF_8);
HttpConnectionParams.setStaleCheckingEnabled(connectionParameters , false);
HttpConnectionParams.setConnectionTimeout(connectionParameters , 4 * 1000);
HttpConnectionParams.setSoTimeout(connectionParameters , 5 * 1000);
HttpConnectionParams.setSocketBufferSize(connectionParameters , 8192);
HttpClientParams.setRedirecting(connectionParameters , false);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("https", (SocketFactory) socketFactory , 443));
ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(connectionParameters, registry);
HttpClient httpClient = new DefaultHttpClient(connectionManager, connectionParameters);
return httpClient;
}
That´s the CastException while register the new build Scheme to the SchemeRegistry
W/System.err(343): java.lang.ClassCastException: org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl cannot be cast to org.apache.http.conn.scheme.SocketFactory
public class SimpleSSLSocketFactory extends
org.apache.http.conn.ssl.SSLSocketFactory {
private javax.net.ssl.SSLSocketFactory sslFactory = HttpsURLConnection
.getDefaultSSLSocketFactory();
public SimpleSSLSocketFactory(KeyStore truststore)
throws NoSuchAlgorithmException, KeyManagementException,
KeyStoreException, UnrecoverableKeyException {
super(null);
try {
SSLContext context = SSLContext.getInstance("TLS");
TrustManager[] trustAllCerts = new TrustManager[] { new
X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
} };
// Initialize the socket factory
context.init(null, trustAllCerts, new SecureRandom());
sslFactory = context.getSocketFactory();
} catch (Exception e) {
e.printStackTrace();
}
}
#Override
public Socket createSocket(Socket socket, String host, int port,
boolean autoClose) throws IOException, UnknownHostException {
return sslFactory.createSocket(socket, host, port, autoClose);
}
#Override
public Socket createSocket() throws IOException {
return sslFactory.createSocket();
}
}
U can call like this
try {
SSLSocketFactory sslFactory = new SimpleSSLSocketFactory(null);
sslFactory
.setHostnameVerifier(SSLSocketFactory.
ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory
.getSocketFactory(), 80));
registry.register(new Scheme("https", sslFactory, 443));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(
params, registry);
DefaultHttpClient httpClient = new DefaultHttpClient(ccm, params);
HttpPost httpPost = new HttpPost(url);
HttpHost proxy = new HttpHost("50.104.5.277", 23333);
//httpPost.setHeader("Content-Type", "text/xml");
httpPost.setEntity(entity);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
proxy);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
output = EntityUtils.toString(httpEntity);
// Toast.makeText(getApplicationContext(), xml, 1000).show();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnrecoverableKeyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (KeyStoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return output;
}

Android 4.0.3 https post returns empty, http works, both works on 2.0.3

I'm connecting my Application to a REST type webservice. I'm using the apache http library, the request is a standard post request, ran in a background thread.
Now my problem is that if I'm using
http://myserver.com/api/command
it works and I get the proper response, but the same url with https:
https://myserver.com/api/command
I get an empty response. The http header is even 200 OK.
BOTH of these work on 2.0.3 but not on 4.0.3. On 4.0.3 the API seems to work only if I use plain http, with https I get empty responses.
This is the code:
#Override
protected HttpResponse doInBackground(String... params) {
String link = params[0];
HttpClient client = createHttpClient();
try {
HashMap<String, ContentBody> files = ApiManager.getFiles();
MultipartEntity mpEntity = new MultipartEntity();
if(files != null) {
for(String i : files.keySet()) {
ContentBody k = files.get(i);
mpEntity.addPart(i, k);
}
}
if(this.callParameters != null) {
for(NameValuePair i : this.callParameters) {
StringBody sb = new StringBody((String)i.getValue(),"text/plain",Charset.forName("UTF-8"));
mpEntity.addPart(i.getName(), sb);
}
}
httppost.setEntity(mpEntity);
// Execute HTTP Post Request
Log.d("ApiTask","Executing request: "+httppost.getRequestLine());
HttpResponse response = null;
response = client.execute(httppost);
client.getConnectionManager().shutdown();
return response;
}
catch(UnknownHostException e) {
exception = e;
return null;
}
catch (IOException e) {
exception = e;
return null;
}
catch(Exception e) {
return null;
}
}
#Override
protected void onPostExecute(HttpResponse result) {
System.out.println("STATUS:"+result.getStatusLine());
try {
StringBuilder responseText = this.inputStreamToString(result.getEntity().getContent());
System.out.println("RESPONSE:"+responseText);
}
catch(Exception e) {
System.out.println("Error");
}
}
private HttpClient createHttpClient() {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
HttpProtocolParams.setUseExpectContinue(params, true);
HttpConnectionParams.setConnectionTimeout(params, 10000);
HttpConnectionParams.setSoTimeout(params, 10000);
SchemeRegistry schReg = new SchemeRegistry();
schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);
return new DefaultHttpClient(conMgr, params);
}
Thank you in advance

org.apache.http.client.ClientProtocolException

I've made an Android application that uses a X509 certificate (that is in the folder res/raw/mykeystore.bks) to sign to remote server that respond on the 9006 port.
the server ask me for a login (username, password).
when i make an HTTPGet i've the following exeption:
org.apache.http.client.ClientProtocolException
Here is my implementation:
The main Activity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b= (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
CredentialsProvider credProvider = new BasicCredentialsProvider();
credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials("rat#1", "rat"));
HttpClient client = new MyHttpClient(getApplicationContext());
((AbstractHttpClient) client).setCredentialsProvider(credProvider);
//final String url = "https://211.92.106.38:9006/KPIRest/testKpi/6";
final String url = "https://211.92.106.38/KPIRest/testKpi/6";
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse response = client.execute(httpGet);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
Custom Client Class:
public class MyHttpClient extends DefaultHttpClient {
final Context context;
public MyHttpClient(Context context) {
this.context = context;
}
#Override
protected ClientConnectionManager createClientConnectionManager() {
KeyStore trustStore = null;
trustStore = KeyStore.getInstance("BKS");
InputStream in = context.getResources().openRawResource(R.raw.mykeystore);
try {
// Initialize the keystore with the provided trusted certificates
// Also provide the password of the keystore
trustStore.load(in, "root01".toCharArray());
}
} finally {
in.close();
}
SSLSocketFactory sf=null;
sf = new MySSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 9006));
return new SingleClientConnManager(params, registry);
}
}
My Customc SSLSoketFactory class:
public class MySSLSocketFactory extends SSLSocketFactory {
SSLContext sslContext = SSLContext.getInstance("TLS");
public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
super(truststore);
TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
sslContext.init(null, new TrustManager[] { tm }, null);
}
#Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {
return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
}
#Override
public Socket createSocket() throws IOException {
return sslContext.getSocketFactory().createSocket();
}
}
what's wrong in my application? What causes that Exception?
Thank you all!
EDIT:
I was looking better the exception:
cause=
org.apache.http.auth.MalformedChallengeException: Authentication challenge is empty.
EDIT 2:
I've tryed to use this implementation with no difference, I've the same exception!
EDIT 3: I've replaced
CredentialsProvider credProvider = new BasicCredentialsProvider();
credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials("rat#1", "rat"));
client).setCredentialsProvider(credProvider);
with the base httpclient autentication, adding the header Authorization to the httpGet:
httpGet.addHeader("Authorization", "Basic "+Base64.encodeToString("rat#1:rat".getBytes(),Base64.DEFAULT));
now the server send me this message:
HTTP/1.1 400 Bad Request
the problem was the Authorization header.
We have to use:
httpGet.addHeader("Authorization", "Basic "+Base64.encodeToString("rat#1:rat".getBytes(),Base64.NO_WRAP));
Instead of:
httpGet.addHeader("Authorization", "Basic "+Base64.encodeToString("rat#1:rat".getBytes(),Base64.DEFAULT));
because the DEFAULT parameter add "CR" line terminator at the end of string and it's uncorrect if you'll use it that header.

Categories

Resources