| View previous topic :: View next topic |
| Author |
Message |
karl
Joined: 07 Sep 2009 Posts: 2
|
Posted: Mon Sep 07, 2009 2:43 pm Post subject: Certificate was issued by an unrecognized entity |
|
|
Hi all,
Well, i'm developing a midlet, and i need to establish a connection to a secure website. I do this through a HttpConnection. Eveything is going fine if i try to connect to an unsecured website.
But i need to connect to a secured website and the CA of the certificate of this website is not trusted by j2me and i get of course an " Certificate was issued by an unrecognized entity" exception.
Sa here is my question. How can i get the public certificate from the website and import it through netbeans into j2me as trusted?
Here is the method I use to connect and retrieve the source code of the webpage. Maybe i misunderstood some...
public String connectHttp(String url) throws Exception {
HttpConnection c = null;
InputStream is = null;
StringBuffer b = new StringBuffer();
boolean permMoved = false;
try {
int len = 0;
int ch = 0;
String username = getLoginScreen().getUsername();
String password = getLoginScreen().getPassword();
String userPassword = username + ":" + password;
String encoding = Base64Converter.encode(userPassword.getBytes());
getWaitScreen().setText("Forbinder...");
c = (HttpConnection) Connector.open(url);
c.setRequestProperty("Authorization", "Basic " + encoding);
permMoved = (c.getResponseCode() == HttpConnection.HTTP_MOVED_PERM) || (c.getResponseCode() == HttpConnection.HTTP_MOVED_TEMP);
if (permMoved) {
getWaitScreen().setText("Siden er flyttet... Omdirigeres...");
} else if (c.getResponseCode() == HttpConnection.HTTP_OK) {
getWaitScreen().setText("Henter siden...");
}
is = (InputStream) c.openInputStream();
// // length of content to be read.
len = (int) c.getLength();
if (len != -1) {
// Read exactly Content-Length bytes
for (int i = 0; i < len; i++) {
if ((ch = is.read()) != -1) {
b.append((char) ch);
}
}
} else {
// Read until connection is closed.
while ((ch = is.read()) != -1) {
len = is.available();
b.append((char) ch);
}
}
//getWaitScreen().setText("Siden hentet... parser...");
} catch (Exception e) {
//String rc=c.getResponseMessage();
e.printStackTrace();
String s = e.toString();
if (s != null) {
return ("http error " + s);
}
} finally {
if (is != null) {
try {
is.close();
} catch (Exception ce) {
}
}
if (c != null) {
try {
c.close();
} catch (Exception ce) {
}
}
}
if (permMoved) {
return connectHttp(getNewAddress(b.toString()));
} else {
return b.toString();
}
}
Thanks,
Karl |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|
|