blackberry中的身份验证用户名密码url

blackberry中的身份验证用户名密码url,url,blackberry,Url,Blackberry,我正在设置一个连接到一个需要用户名和密码的站点,但是它没有连接,我不知道原因,你能帮我吗 这是我正在使用的代码 { 高温超导连接; 连接=(HttpsConnection)连接器。打开(url+ getBlackBerryConnectionParams()); connection.setRequestProperty(“授权”、“基本”+ 新字符串(getEncode()); } 公共字节[]getEncode(){ String login=“用户:@@

我正在设置一个连接到一个需要用户名和密码的站点,但是它没有连接,我不知道原因,你能帮我吗

这是我正在使用的代码

{
高温超导连接;
连接=(HttpsConnection)连接器。打开(url+
getBlackBerryConnectionParams());
connection.setRequestProperty(“授权”、“基本”+
新字符串(getEncode());
}                  
公共字节[]getEncode(){
String login=“用户:@@iPass”;
字节[]编码=空;
试一试{
encoded=Base64OutputStream.encode(login.getBytes(),0,
login.length(),false,false);
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
返回编码;
}

实际密码以“@@”开头,并且有一个大写字母

请尝试以下代码

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();
我发现代码中有几个潜在的问题

首先,也是最简单的一个,这行中“Basic”一词后面似乎缺少一个空格

connection.setRequestProperty(“授权”、“基本”+
新字符串(getEncode());
“Basic”
更改为
“Basic”

其次,您将使用url向Web服务器传递授权凭据。正常情况下,没关系。但是,另一种方法是等待Web服务器挑战您。如果您查看此线程:

见MSohm的回复:

如果您使用的是BlackBerry Enterprise Server(或MDS-CS 模拟器),请记住这一点:

使用抢占式连接时BlackBerry MDS连接服务出现问题 认证

看起来,如果您的传输是BES或MDS,那么这也可能会给您带来问题。如果您选择其他传输方式(如直接TCP或Wi-Fi),则这可能不是问题

以下是关于BlackBerry(RIM)

我如何使用以下代码(不记得在哪里找到它)作为自定义Ntlm连接器实现的起点的参考文档。它工作得很好。希望它能帮助你。

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;
    }

}

事实上和我上面写的一样有什么区别!“Basic”后面缺少一个空格。但是,可能还有另一个问题。。。见下面我的答案。