Authentication username password url in blackberry

I am setting up a connection with a site that requires a username and password, but it does not connect, and I do not know why you can 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 starts with "@@" and there is a capital letter

0
source share
3 answers

Please try the following code.

 String URL = "URL"+methodName+parameterString+"deviceside=true"; connection = (HttpConnection) Connector.open(URL); String authenticationParameter = "username"+":"+"password"; byte[] encoded = Base64OutputStream.encode(authenticationParameter.getBytes(), 0, authenticationParameter.length(), false, false); connection.setRequestProperty("Authorization", "Basic "+ new String(encoded)); rc = connection.getResponseCode(); 
0
source

I see a couple of potential code issues.

First, and the simplest, is that it seems to you that there is no space after the word "Basic" in this line

 connection.setRequestProperty("Authorization", "Basic" + new String(getEncode())); 

Change "Basic" to "Basic " .

Secondly, you pass the authorization credentials to a web server with a URL. This is usually normal. But another way to do this is to wait for the web server to call you. If you look at this topic:

http://supportforums.blackberry.com/t5/Java-Development/HTTPS-Net-Web-Service-with-Basic-authentication/td-p/1615931

See MSohm answer:

If you are using a BlackBerry Enterprise Server (or MDS-CS Simulator), keep this in mind:

Problems with the BlackBerry MDS Connectivity service when using Pre-emptive Authentication

It looks like if your transport is BES or MDS, it can also cause problems. If you choose another transport (for example, direct TCP or Wi-Fi), then this is probably not a problem.

In this white paper on how BlackBerry (RIM) offers you these requests

0
source

I used the following code (I don’t remember where I found it) as a starting point for a custom implementation of the Ntlm Connector. It worked fine. Hope this can help you.

 package net; import java.io.IOException; import javax.microedition.io.Connector; import javax.microedition.io.HttpConnection; import javax.microedition.io.StreamConnection; import net.rim.device.api.io.Base64OutputStream; public class NtlmConnector implements IConnector { private String url; private String domain; private String username; private String password; public NtlmConnector(String url, String domain, String username, String password) { this.url = url; this.domain = domain; this.username = username; this.password = password; } private HttpConnection openAuthenticatedConnection() throws IOException { StreamConnection netStream = (StreamConnection)Connector.open(url); HttpConnection httpConnection = (HttpConnection)netStream; String credentials = domain + "\\" + username + ":" + password; byte[] encodedCredentials = Base64OutputStream.encode(credentials.getBytes(), 0, credentials.length(), false, false); httpConnection.setRequestProperty("Authorization", "Basic " + new String(encodedCredentials)); return httpConnection; } private void mapResultToConnectionStatus(ConnectorResult result, int connectionStatus) { switch (connectionStatus) { case (HttpConnection.HTTP_OK): result.setConnectionDone(true); break; case (HttpConnection.HTTP_UNAUTHORIZED): result.setConnectionDone(false); //TODO: add detailed error break; default: result.setConnectionDone(false); break; } } public ConnectorResult connect() { ConnectorResult result = new ConnectorResult(); try { HttpConnection connection = openAuthenticatedConnection(); int responseStatus = connection.getResponseCode(); connection.close(); mapResultToConnectionStatus(result, responseStatus); } catch (IOException e) { //TODO: map into result error detail } return result; } } 
0
source

All Articles