So, on my site, I use a couple different SSL cerficates. One for the root domain "illution.dk" and one for my subdomain "ci.illution.dk". Trouble is, when I fire a post request using HttpPost, and I request a URL like "https://ci.illution.dk/login/device", it just throws an error message saying:
10-04 18:35:13.100: W/System.err(1680): javax.net.ssl.SSLException: hostname in certificate didn't match: <ci.illution.dk> != <www.illution.dk> OR <www.illution.dk> OR <illution.dk>
I think this means that it is downloading the certificate of illution.dk, and then seeing that it does not support ci.illution.dk. However, everything is fine when I load up the browser and browse to "https://ci.illution.dk". My Android code is as follows:
HttpClient httpclient = new DefaultHttpClient();
//appContext.getString(R.string.base_url)
HttpPost httppost = new HttpPost("https://ci.illution.dk/login/device");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", params[0]));
nameValuePairs.add(new BasicNameValuePair("password", params[1]));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httppost.addHeader("Content-Type", "application/x-www-form-urlencoded");
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
return response;
} catch (ClientProtocolException e) {
Log.d("ComputerInfo", "Error while loggin in: ClientProtocolException");
return null;
} catch (IOException e) {
Log.d("ComputerInfo", "Error while loggin in: IOException");
e.printStackTrace();
return null;
} catch (Exception e) {
Log.d("ComputerInfo", "Error while loggin in");
e.printStackTrace();
return null;
}
Ok, it seems that it is an error with HttpPost, because if I use the code linked here it just works. I have modified the code to suit my specific needs, but here is my code: (Just in case the link goes down)
just look at the code at the following you would get the answer. I have used it in my code. You have to use in your code.
BufferedReader reader = new BufferedReader(new InputStreamReader( is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");}
is.close();
Take a look at following example i have used in it