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. Can someone explain the correct way to use android:layout_toRightOf?





Actually, forward references work in Android 1.6+, but you have to put
the + sign on the @+id the *first* time it is encountered. So, in this
snippet, put @+id/bucm in the toRightOf, and when you define the widget
later in the layout, give it an android:id of @id/bucm, and it works.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

_Android Programming Tutorials_ Version 1.1 Available!

-- 

2. What is Rasterizer?

hi,

i'm trying to understand Paint.setRastezer method

it seems there is only one concrete Rasterizer - LayerRasterizer class

so i created one and added two layers - addLayer(Paint, int, int)

after calling drawSomething it seems that "Something" is drawn twice
with offset specified by two ints passed to addLayer method.

what layer's Paint attributes are used during drawing each layer? i
tried adding some Shader to each layer and got process death - no java
exception, just {*filter*}ed my process...

thanks,
pskink

-- 

3. RenamingDelegatingContext overwrites existing database file - bug?

4. Issue with simultaneous audio playback and recording

5. Error while booting 32 kernel with eclair RFS on beagle

6. How long does it take for an application to get indexed to the Marketplace?

7. Avoiding garbage collection for smooth 2d animations