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. Pretty code program (for all developers)...

Recently, as I was asking for help on IRC I posted my code. Someone said it
looked ugly. Of course, there are many coding preferences and one of them is
spacing style. I was thinking about writing  a simple vim plugin that could
reformat source code to make it look according to a sample, and then I
thought, since I don't have much experience out there, and there are lots of
different languages that might handle this much much better than a
cumbersome and lengthy program in C to handle strings, I thought perhaps
that I might ask for some opinions and directions on this. C/C++ program or
vim plugin? Or what's more, it could be something that I haven't thought of
yet.

The program should perform code tidying up and would be well suited to run
before a make command.

I think that it should offer spacing and indenting options as well as some
comment formatting options. These should be able to be set by a gui that
offers an abstract and quick way to set it. Otherwise, the user would have
to learn even *more* commands and that's the last thing that I want. I want
an abstract gui that will be easy to set.

This will offer very regular code formatting. Say you have a lot of nested
calls and you don't want to use tabs with space 8 because if you do it will
keep on trailing off the screen. Also, frequently there are often commands
that we like to use, but they are long. like... cout << "very long text";
and we don't want to redo each of them individually, it would take forever.
or say someone else used an editor that it looked good in and now you use
yours and it looks like crap. whatever the reason, i want a tool that can be
run like a command but will offer a gui to format the code.

After thinking this over, I've come up with a lot of ideas about how this
could be managed to provide a set of features/options that I don't want to
describe here.

If you guys know of any other tools that do anything of the sort like what
i've described here, I'd like to know what they are so that I don't start
another project only to find that someone else has already created something
similar. Or if you have any suggestions, send them my way, or perhaps you
don't think that this project is worth a shot-whatever it is, speak out
about it.

2. Source branches and Android versions

I am compiling the Android source following the instructions at
http://source.android.com/download. But no where does it talk about
the version of the current master branch and the relationship between
the source branch and the different versions - 1.6, 2.0.1, and 2.1.

What is the current version of the master branch?

How can I download different versions of the source code, namely 1.6,
2.0.1 and 2.1 from the git repository?

Is there a complete list of all available branches?

Thanks.

3. camera setPreviewSize, on Nexus One, apiVersion 7

4. Instructions to install Android on Netbook

5. android.backup package

6. Launch updated emulator?

7. Service callback to Activity