I'm setting up a connection to a site which requires a username and password but it doesn't connect and I don't know the reason can you help me with this please?
This is the code I'm using
{
HttpsConnection connection;
connection = (HttpsConnection) Connector.open(url +
getBlackBerryConnectionParams());
connection.setRequestProperty("Authorization", "Basic" +
new String(getEncode()));
}
public byte[] getEncode() {
String login = "user:@@iPass";
byte[] encoded = null;
try {
encoded = Base64OutputStream.encode(login.getBytes(), 0,
login.length(), false, false);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return encoded;
}
The actual password does start with "@@" and there's a capital letter
Please try following code..
I used the following code (don't remember where I found it) as starting point for a custom Ntlm Connector implementation. It worked fine. Hope it may help you.
I see a couple potential problems with the code.
First, and the simplest one, is that you seem to be missing a space after the word "Basic" in this line
Change
"Basic"
to"Basic "
.Secondly, you are passing the authorization credentials to the webserver with the url. Normally, that's ok. But, another way to do it is to wait for the webserver to challenge you. If you look at this thread:
http://supportforums.blackberry.com/t5/Java-Development/HTTPS-Net-Web-Service-with-Basic-authentication/td-p/1615931
See MSohm's response:
It looks like, if your transport is BES or MDS, then this also might cause you problems. If you pick another transport (e.g. direct TCP, or Wi-Fi), then this probably isn't an issue.
Here's the reference document on how BlackBerry (RIM) suggests you make these requests