Help Center
Local Navigation
- Creating user interfaces
- Storing data
- Creating connections
- Network gateways
- Connections
- Wi-Fi connections
- Wireless access families
- Retrieve the wireless access families that a BlackBerry device supports
- Determine if a BlackBerry device supports multiple wireless access families
- Determine the wireless access family transceivers that are turned on
- Turn on the transceiver for a wireless access family
- Turn off the transceiver for a wireless access family
- Check if the Wi-Fi transceiver is turned on
- Check if the Wi-Fi transceiver is connected to a wireless access point
- Retrieve the status of the wireless access point or the active Wi-Fi profile
- Open a Wi-Fi socket connection
- Open a Wi-Fi HTTP connection
- Open a Wi-Fi HTTPS connection
- Managing applications
- Using custom messages and folders in the message list
- Applications for push content
- Localizing BlackBerry device applications
- Controlling access to APIs and application data
- Testing a BlackBerry device application
- Packaging and distributing a BlackBerry Java Application
- Glossary
- Provide feedback
- Legal notice
BlackBerry Manuals & Help
>
Documentation for Developers
>
Java Development Guides and API Reference
>
Development Guide - BlackBerry Java Development Environment - 4.7.0
Use HTTP authentication
- Import the following classes:
- Import the following interfaces:
- Use the CoverageInfo class and CoverageStatusListener interface of the net.rim.device.api.system package to verify that the BlackBerry device is in wireless network coverage area.
- Invoke Connector.open(), using the HTTP location of the protected resource.
- Cast and store the returned object as a StreamConnection.
StreamConnection s = (StreamConnection)Connector.open("http://mysite.com/myProtectedFile.txt"); - Cast and store the StreamConnection object as an HTTPConnection object.
HttpConnection httpConn = (HttpConnection)s;
- Invoke HttpConnection.getResponseCode().
int status = httpConn.getResponseCode();
- Create code to manage an unauthorized HTTP connection attempt.
int status = httpConn.getResponseCode(); switch (status) case (HttpConnection.HTTP_UNAUTHORIZED);
- Create a run()method and within it implement a dialog object to ask the BlackBerry device user for login information.
UiApplication.getUiApplication().invokeAndWait(new Runnable()) { public void run() { dialogResponse = Dialog.ask; (Dialog.D_YES_NO,"Unauthorized Access:\n Do you wish to log in?"); } } - To process the login information, create code to manage a Yes dialog response.
- Invoke HTTPConnection.setRequestProperty() using the encoded login information to access the protected resource.
s = (StreamConnection)Connector.open("http://mysite.com/myProtectedFile.txt "); httpConn = (HttpConnection)s; httpConn.setRequestProperty("Authorization", "Basic " + new String(encoded));
Parent topic: Connections