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 ***", "2222222"); HttpParams params = new BasicHttpParams(); ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>(); postParameters.add(new BasicNameValuePair("username", edtusername.getText().toString())); postParameters.add(new BasicNameValuePair("password", edtpassword.getText().toString())); Log.i("before socket is registered ***", "33333333"); // 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 ***", "44444"); String url = "https://192.168.10.106/check_admin.php? method=check_admin&username=admin&password=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)); SingleClientConnManager mgr = new SingleClientConnManager( client.getParams(), registry); DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams()); // Set verifier HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); HttpPost post = new HttpPost(url); // cl = new DefaultHttpClient(); // try { // post.setEntity(new UrlEncodedFormEntity(postParameters)); // } catch (UnsupportedEncodingException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // } try { HttpResponse res = httpClient.execute(post); InputStream in = res.getEntity().getContent(); byte[] bytes = new byte[in.available()]; in.read(bytes); String s = new String(bytes); Log.i("the string value is", "***" + s); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } }*********************** pls advice me some thing on it... i m totally clue less On Sep 13, 8:13 pm, b0b <pujos.mich...@gmail.com> wrote: > 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