View Single Post
Old 10-02-2006, 09:42 PM   #3
fbrimm
Thumbs Must Hurt
 
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Posts: 144
Default

whickie,

Not sure if this is your problem or not, but I read somewhere in the RIM documentation that its best if you fire up the browser on the simulator and just hit a normal page (ie, google.com). After that it should work with your app. Apparently you have to "prime the pump".

I have not run into the problems you are seeing, and am able to authenticate to an external web server through the MDS simulator just fine. I have not tried to authenticate with a web server running on the same machine. Have you tried running your web server on a different machine than where your MDS simulator and device simulator are running?

Can you post the section of your code where you are trying to do the authentication from? It might be helpful to see exactly what you are doing.

Here is a snipet of code that I use to authenticate and read a file from a url.

fbrimm

Code:
String login = "username:password";
String url = "http://myurl.com/mypage;deviceside=false";
HttpConnection c = null;
InputStream dis = null;
String userData = "";
boolean keepGoing = true;
int response;

try {
    // Encode the login information in Base64 format.
    byte[] encoded = Base64OutputStream.encode(login.getBytes(), 0, login.length(), false, false);
    
    c = (HttpConnection)Connector.open(url);
    
    while (keepGoing) {
        int status = c.getResponseCode();
        switch (status) {
            case (HttpConnection.HTTP_OK):
                // Connection is 200 OK.
                // Download and process data.
                keepGoing = false;
                break;
                        
            case (HttpConnection.HTTP_UNAUTHORIZED):
                // Connection is 401 UnAuthorized.
                // A login and password is required.
                c.close();
                        
                // Open a new connection.
                c = (HttpConnection)Connector.open(url);
                        
                // Add the authorized header.
                c.setRequestProperty("Authorization", "Basic " + new String(encoded));
                break;
                        
            case (HttpConnection.HTTP_NOT_FOUND):
                // File not found
                Dialog.inform("File not found\n"+url);
                System.exit(-1);
                break;
                        
            default:
                // The connection failed for some other reason.
                        
                Dialog.inform("Connection failed\nStatus = "+status+"\nClosing app");
                System.exit(-1);
                break;
        }
    }

    // You can now read your file...

    dis = c.openDataInputStream();

    StringBuffer sb = new StringBuffer();
    int ch;
    while ((ch = dis.read()) != -1) {
        sb.append((char) ch);
    }
    userData = sb.toString();
} catch (IOException ioe) {
    System.out.println(ioe.toString());
} finally {
    if (dis != null) {
        try {
            dis.close();
        } catch (Exception e) {
        }
    }
    if (c != null) {
        try {
            c.close();
        } catch (Exception e) {
        }
    }
}
Offline