[android-developers] Re: SSL certificate error for authenticating the credentials

2011-09-14 Thread Atik
Hello

I have added all the stuff in my code, but i m confused how to do for
https. can u pls elaborate more abt the truststore,
 how to create it and if u sample then it would be great.

i have modified the code in different ways but i m unable to get
output

my code is 

package com.example;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
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.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.SingleClientConnManager;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class LoginDemoActivity extends Activity {

EditText edtusername, edtpassword;
Button btnsignin;
DefaultHttpClient cl;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);

edtusername = (EditText) findViewById(R.id.username);
edtpassword = (EditText) findViewById(R.id.password);
btnsignin = (Button) findViewById(R.id.btnsignin);

btnsignin.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Log.i(the username is + 
edtusername.getText().toString(),
the password is + 
edtpassword.getText().toString());
Log.i(before arraylist ***, 222);

HttpParams params = new BasicHttpParams();

ArrayListNameValuePair postParameters = new
ArrayListNameValuePair();
postParameters.add(new 
BasicNameValuePair(username,

edtusername.getText().toString()));
postParameters.add(new 
BasicNameValuePair(password,

edtpassword.getText().toString()));

Log.i(before socket is registered ***, 
);

// SchemeRegistry schemeRegistry = new 
SchemeRegistry();
// schemeRegistry.register(new Scheme(http,
// PlainSocketFactory.getSocketFactory(), 80));
// schemeRegistry.register(new Scheme(https, 
new
// EasySSLSocketFactory(), 443));
// ClientConnectionManager conMgr = new
// ThreadSafeClientConnManager(
// params, schemeRegistry);

// cl= new DefaultHttpClient(conMgr,params);

Log.i(after socket is registered ***, 
4);

String url = 
https://192.168.10.106/check_admin.php?
method=check_adminusername=adminpassword=spsoft_123;

HostnameVerifier hostnameVerifier =
org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
DefaultHttpClient client = new 
DefaultHttpClient();

SchemeRegistry registry = new SchemeRegistry();
SSLSocketFactory socketFactory = 
SSLSocketFactory
.getSocketFactory();


socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
socketFactory

.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
registry.register(new Scheme(https, 
socketFactory, 443));

[android-developers] Re: SSL certificate error for authenticating the credentials

2011-09-13 Thread b0b
use this for your SSL factory:

SSLSocketFactory sslFactory = SSLSocketFactory.getSocketFactory();
sslFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);


But since you didn't specify a truststore with the certificate of the 
server, you'll probably have another error.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en