need help on https (code for http included)

by Marco Schmitz » Sat, 05 Sep 2009 02:17:38 GMT


Sponsored Links
 hank you droidin,

unfortunately I didnt need the httpclient but the stream.

well, I found a solution :)

btw: this is sdk 1.1 r1 code:

greetings,
marco

------------------------------------------------------------------------
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import lgpl.haustein.Base64Encoder;

import org.apache.log4j.Appender;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Layout;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.spi.LoggingEvent;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

/**
* Hyper
*/
public class Hyper extends Activity {

private static Logger logger = Logger.getLogger(Hyper.class);

private static final String HTTP = "http://www.gmx.de";
private static final String HTTPS = "https://www.verisign.com/";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
logger.debug("START");

try {
SSLContext sc = SSLContext.getInstance("TLS");
scinit(null, new TrustManager[] { new MyTrustManager()
}, new
SecureRandom());

HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new
MyHostnameVerifier());
HttpsURLConnection con = (HttpsURLConnection) new
URL(HTTPS).openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.connect();

BufferedReader br = new BufferedReader(new
InputStreamReader(con.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null)
sb.append(line);

logger.debug("InputStream: " + sb.toString());

logger.debug("END");
} catch (Exception e) {
logger.error(e);
}
}

/**
* MyHostnameVerifier
*/
private class MyHostnameVerifier implements HostnameVerifier {

@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}

/**
* MyTrustManager
*/
private class MyTrustManager implements X509TrustManager {

@Override
public void checkClientTrusted(X509Certificate[] chain, String
authType) {
}

@Override
public void checkServerTrusted(X509Certificate[] chain, String
authType) {
}




Other Threads

1. Computer Vision / Image Processing

Android Developers:

I am looking to develop native Android libraries for computer vision
and image processing. I am an experienced C++ developer, and have a
great deal of experience with OpenCV.

What I'm looking for:

Information about how Android handles cameras. I am well aware of the
basics that are available in the android references (getting a camera
object, starting a preview, etc) but I need further information about
the pixel information can be obtained. Results on the internet are
shoddy at best ( most of them are for older versions of Android ) but
I've found so far that the camera uses YUV colorspace, and thats
pretty much it.

Pointing me in the right direction would be awesome, or links/articles/
references/examples are fantastic as well.

If anyone would like to assist in development, I can start a google
code project. (Yes, i've seen that there is at least 1, called
androidcv, already. There is no activity, so we can request owner
change from the owner or start another one).

Regards,

Myles

-- 

2. Reading assets directory without AssetManager

I am porting some existing code to android.  I have some data files
that I need to put in the assets directory (or some comparable place
in the package).  The code I'm porting wants a path to the directory
containing the data files, in this case "assets".  However, it seems
like android won't let you access the assets directory directly
without AssetManager.  I assume this has to do with localization
issues.

So if I know I placed a resource "Data.dat" in assets, is there any
way to get a path to it so I can open it with something like:

FileInputStream in = new FileInputStream(path);

I really need a path to the resource.  I can't use

AssetManager assetMgr = this.getAssets();
InputStream in = assetMgt.open(filename);

Is this possible?

Thanks.

-- 

3. AccountManager's storage

4. access to network from native code

5. Who's handling hard key long press?

6. Question about Launcher layout file

7. Google Maps web service