HTTPS connection to the server using the connection

Hello! It is a part of my code to connect to a secure server.

However, it is not show me if the connection has been connected. Is there something wrong with my code?

' Public Sub validateUser (String usernamelogin, String passwordlogin) throws IOException {}

HttpsConnection httpConn = null;
String url = "https://myserverpage/login?";
InputStream is = null;
OutputStream os = null;
    
Cookie string ="";
Params string;
params = 'name =' + usernamelogin;
params += "& password =" + passwordlogin.replace (' ', '+');

try {}
Open an HTTPs connection object
httpConn = (HttpsConnection) Connector.open (url + params);
Setup HTTP POST request
httpConn.setRequestMethod (HttpsConnection.POST);

httpConn.setRequestProperty ("Cookie", cookie);
httpConn.setRequestProperty ("Accept_Language", "en-US");
Content-Type is essential to pass parameters in a POST request
httpConn.setRequestProperty ("Content-Type", "application/x-www-formulaires-urlencoded");
      
      
      
httpConn.setRequestProperty ("name", usernamelogin);
httpConn.setRequestProperty ("password", passwordlogin);
      
secure https
If SecurityInfo = httpConn.getSecurityInfo ();
Certificate c = si.getServerCertificate ();
Object String = c.getSubject ();

This function retrieves this connection information
getConnectionInformation (httpConn);

OS = httpConn.openOutputStream ();

OS. Write (params. GetBytes());

/ * ATTENTION: os.flush () is controversial. It can create unexpected behavior
on some mobile devices. Try it for your mobile device * /.

OS. Flush();

Read the response from the server

StringBuffer sb = new StringBuffer();
is = httpConn.openDataInputStream ();
int chr;
While ((chr = is.read (())! = - 1).
SB. Append ((Char) chr);

Web server returns only
System.out.println (usernamelogin + "is connected" + sb.toString ());

} {Finally
If (is! = null)
is. Close();
If (OS! = null)
OS. Close();
If (httpConn! = null)
httpConn.close ();
}

}

The fact of this aid.

http://supportforums.BlackBerry.com/T5/Java-development/implement-basic-HTTP-authentication/Ta-p/445...

Tags: BlackBerry Developers

Similar Questions

  • How to write a program that allows an HTTPs connection to the APACHE TOMCAT server in blackberry JDE

    Hello.. I am very new to the blackberry JDE environment. But then, I have a project in which I should write a program that will make an HTTPs connection to the apache tomcat server using blackberry JDE. The simulator which I use is 8330-JDE.

    Here is my code...

    import java.io.IOException;

    Import java.io.InputStream;

    Import javax.microedition.io.Connector;

    Import javax.microedition.io.HttpsConnection;

    Import net.rim.device.api.ui.UiApplication;

    Import net.rim.device.api.ui.container.MainScreen;

    public class Httproto extends UiApplication

    {

    public public static void main (String [] args)

    {

    Httproto instance = new Httproto();

    instance.enterEventDispatcher ();

    }

    public Httproto()

    {

    pushScreen (new HttpsConnectionScreen());

    }

    }

    final class HttpsConnectionScreen extends screen

    {

    public HttpsConnectionScreen()

    {

    HttpsConnection c = null;

    InputStream is = null;

    int rc;

    try {String url =

    "https://192.168.2.3: 8443/cit/j_acegi_security_check? j_username = sanogo & j_password = redhat;

    c = (HttpsConnection) Connector.open (url);

    c.setRequestMethod (HttpsConnection.POST);

    System.out.println ("connection is open with the server");

    Get the response code is open the connection,

    Send the request and read HTTP response headers.

    The headers are stored until asked.

    RC = c.getResponseCode ();

    System.out.println ("response from the server" + rc);

    if (rc! = HttpsConnection.HTTP_OK) {

    throw new IOException ("HTTP response code:" + rc);

    }

    is = c.openInputStream ();

    Get the ContentType

    The string of type = c.getType ();

    The length and process data

    int len = (int) c.getLength ();

    if (len > 0) {

    int actual = 0;

    int BytesRead = 0;

    byte data = new byte[len]; while ((bytesread! = len) & (real! = - 1)) {

    real = is.read (data, bytesread, len - bytesread);

    bytesRead += real;

    }

    } else {}

    int ch;

    while ((ch = is.read (())! = - 1). {

    }

    }

    } catch (ClassCastException e) { throw new IllegalArgumentException ("not a HTTP URL");}

    }

    catch (IOException ioe) {}

    finally {

    Try

    {

    if (is! = null)

    is. Close();

    if (c! = null)

    c.Close ();

    }

    catch (IOException ioe) {}

    }

    }

    }

    When I run this program in the Simulator, I can do nothing. Please correct me if I'm wrong in coding.

    As I am new to this blackberry JDE environment, ideas and suggestions on how to write and run the sample applications in the blackberry are more welcomed.

    Concerning

    Hinduja

    Make sure that your MDS starts when the Simulator starts.  In the JDE will in Edition > Preferences > Simulator > General and click the checkbox "launch Mobile Data System connection with Simulator Service.

  • How to get the gif file hosted by using the Http connection?

    Hello

    I have an application that downloads animation gif from a server by using the http connection. Here is the code I use to download the image.

    try {
    
                httpConnection = (HttpConnection) Connector.open(url, Connector.READ_WRITE);            httpConnection.setRequestMethod(HttpConnection.GET);
    
                if (httpConnection.getResponseCode() == HttpConnection.HTTP_OK) {                DataInputStream dS = httpConnection.openDataInputStream();
    
                    byte[] data = new byte[dS.available()];                dS.read(data);
    
                    gifImage = (GIFEncodedImage) EncodedImage.createEncodedImage(data, 0,data.length);
    
                } else {                throw new Exception("ResponseCode:" + httpConnection.getResponseCode());            }        } catch (Exception e) {                        gifImage = null;            e.printStackTrace();        }
    

    the problem with this code is, when the gif file is 1175 bytes above, it does not load the gif.

    example:-If the gif on the server is 1500 bytes, this code retrieves only 1175 bytes.

    I think that the rest of the bytes are sent in a different package. But how to get them.

    can someone please provide a code for buffering the inputstream?

    any help is appreciated.

    Dieye

    Hmm, nobody seems to know how to do, it seems. Here's how I did it.

                httpConnection = (HttpConnection) Connector.open(url, Connector.READ_WRITE);
                httpConnection.setRequestMethod(HttpConnection.GET);
    
                int responseCode = httpConnection.getResponseCode();
                if (responseCode == HttpConnection.HTTP_OK) {
                    inputStream = httpConnection.openInputStream();
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    
                    byte[] buffer = new byte[256];
                    int len = 0, imageSize = 0;
    
                    while (-1 != (len = inputStream.read(buffer))) {
                        byteArrayOutputStream.write(buffer);
                        imageSize += len;
                    }
    
                    byteArrayOutputStream.flush();
                    byte[] imageData = byteArrayOutputStream.toByteArray();
                    byteArrayOutputStream.close();
    
                    gifImage = (GIFEncodedImage) EncodedImage.createEncodedImage(imageData, 0, imageSize);
    
  • HTTPS connection to the server with the host name which has its IP address

    Hi all

    I work in a development of the solution where a server application is running in a machine and hosts of Application Service SOAP over HTTPS. The server has the certificates for its IP address. My client application tries to use the SOAP Service; but when I connect to the Application Server using the HOST name in the URL, I get the SSLException indicating that the HOST name does not match name the object.

    If I use the IP address in the URL, it works well - but I do not like the server application can move to different IP dynamiccaly - if you are using DNS is our solution to hide this complexcity from client applications.

    Help, please.

    Kind regards
    Kaja

    the HOST name does not match name the object.

    The host name does not have the name of the topic in the server certificate. He agrees with host.domain name.

  • "Do you want to view only the webpage content that was delivered safely. "the Web page content that willl be sent using a secure HTTPS connection, which could jeopardize the securityof the entire Web page.

    Original title: SECURITY WARNING

    When I try to open a program I have getthis message:

    "Do you want to view only the webpage content that was delivered safely.

    "the Web page content that willl be sent using a secure HTTPS connection, which could jeopardize the securityof the entire Web page.

    Is this something that needs to be corrected?  If yes how.

    Hi billkabay,

    (1) program which you are referring?

    (2) is the problem confined to this specific programme?

    (3) since when are you facing this problem?

    This problem normally occurs when you open Web pages in internet explore. Please specify if this happens when you open a program or opening a Web page or link in internet explore.

    You can see the steps in the link below

    https://community.dynamics.com/product/crm/crmtechnical/b/crminogic/archive/2009/07/09/how-to-disable-the-34-do-you-want-to-view-only-the-webpages-content-that-was-delivered-securely-63-popup-for-custom-pages-added-to-crm.aspx

    Also see the steps by Vincenzo Di Russo (check the post Saturday, May 30, 2009 11:36) in the link below.

    http://social.answers.Microsoft.com/forums/en-us/InternetExplorer/thread/e7526a5f-F953-4235-90c3-004f9b973585

    Thanks and greetings

    Ajay K

    Microsoft Answers Support Engineer
    ***************************************************************************
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • Application does not connect to the server using WAP2.0

    Hello

    I used following code to get the suffix of the url that is required to connect to the application server using WAP2.0

           if(CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_DIRECT))
            {
                    //WAP 2.0
                String uid = null;
                ServiceBook sb = ServiceBook.getSB();
                ServiceRecord[] records = sb.findRecordsByCid("WPTCP");
                for (int i = 0; i < records.length; i++) {
                    if (records[i].isValid() && !records[i].isDisabled()) {
                        if (records[i].getUid() != null &&
                            records[i].getUid().length() != 0) {
                            if ((records[i].getCid().toLowerCase().indexOf("wptcp") != -1) &&
                                (records[i].getUid().toLowerCase().indexOf("wifi") == -1) &&
                                (records[i].getUid().toLowerCase().indexOf("mms") == -1)   ) {
                                uid = records[i].getUid();
                                break;
                            }
                        }
                    }
                }
    
                if(uid!=null)
                {
                    if(AppConfigurations.DEBUG)
                        System.out.println("Connected using direct WAP2.0....");
                    return ";ConnectionUID="+uid;
                }
            }
    

    I am same ConnectionUID as present in this complete book in Options in the device.

    Even application does not connect to the server using WAP2.0.

    Let me know what other things should I check to make application to connect to the server using WAP2.0.

    My phone is BB 8900 and OS 4.6.1

    WAP connection will pass through the gateway of the carrier.  This gateway can oppose your respect, or might be trying to optimize the data, or can display a login page for you.  Try the same URL that you use in your program, directly with the WAP browser on the device and see if that runs through effectively.

  • cannot reduce the application on end key click on the http connection.

    Hi all

    I use version eclipse3.4 for Blackberry development. In my application, I need to extract data from a Web service via a servlet created by me. I've implemented it using a wire and it works fine.

    But the problem is, after the http connection, when control passes to servlet I can't minimize my application using events end key as a normal application. This fine event key only works when the control back on the side of the unit... My entire application got stuck when he tries to retrieve the data from webservice... Please help me on this.

    Please guide me how to implement the reduction feature in my application when it attempts to retrieve data from the server using the http connection.

    I used this package for connecting

     

    javax.microedition.io.Connector; javax.microedition.io.HttpConnection;

    Please help me on this...

    Advanced thanks and greetings,

    Michel Philippe.

    You will need to run the web service code in a separate thread...

  • 8900 comm http hangs after the second connection (do not view with the 83XX devices or 8900 Simulator)?

    Hello

    I currently have a j2me application that is deployed in production on different devices of BB. The application is pretty simple and mainly collects the data of the user (via text fields, drop-down list boxes etc.) and send these data to our server via an http connection

    The application was deployed in production for more than 6 months and work with end users using various BB devices, like the 8310, 8320 and 9000.

    Our end users now upgrade to the 8900 and we assumed that our application would work in the same way as the 8320-I even tested my app on the Simulator to 8900 and everything works fine.

    However, using the app on a real 8900 device connected to the network Vodafone here in the United Kingdom has cast some weird problems. The app installs fine OTA, communicates initially very well (as we connect via an http post), but then any attempt further communication over http hang everything simply no error thrown?

    Closing the application does not have any change, and blocking any attempt at communication. If I restart the device (battery etc) and start the application then I can connect once more, and then the app just crashes again.

    I can't find the cause, and the fact that other physical devices and even the Simulator to 8900 work very well is weird!

    Any help or pointer to start looking in my code/settings would be appreciated?

    Daniel

    Please make sure you close your connection. or check if the current connection is close before opening another.

  • http connections fail after removing an application via the BES

    This is consistent - happened on three different phones.

    Measures taken since the BES

    1 deploy an application that uses an HTTP (definition of a custom policy of IT) through the BES connection. Everything works fine

    2 remove the app (by its configuration was rejected.)

    3. assign the policy to the default device

    4 configuration of the software place the device no

    5 deploy

    5. wait and check that app has been removed from the default value of advertising device it in place policy

    Now, the unit measures

    1. install the app even through Javaloader - now http connections fails

    On the curve (Rogers)

    java.io.IOException: Tunnel failed

    on Tour (Verizon)

    javax.microedition.io.ConnectionNotFoundException: Protocol not found: net.rim.device.cldc.io. "http. Protocol

    Any ideas?

    Turns out I had put extra quotes in my url string. It works fine now.

    This diagnostic network (DB-00684) tool was very useful.

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is...

  • Hangs on the creation of HTTP connection

    Sometimes to create a connection HTTP crashes (using HTTPConnectionFactory or ConnectionFactory).  This occurs after a number of HTTP connections have been created, used and closed.

    Once again, I have a blockage, if I wait a bit, while I am able to create connections again successfully.

    If I hold down the button end call to suspend the phone in low power mode, it will also address the issue.  When I turn it back on and restart the app, it works.  But if I just restart the application, it won't work.

    I found the problem.  You must call close on the connection, not only the input and output stream.

  • Problem in the http connection. (simulators 5.0 os blackberry 9000 smartphone)

    Hello friends,

    I am doing my project in Eclipse Platform Version: 3.4.1 4.5 os and I'm using the 8300 Simulator. I use the http connection. When I debug my project, I work correctly. I'm download 8300 same Simulator to test the object. It worked correctly in Simulator 8300.

    but when I try 4.7 and 5.0 for Simulator that I download this Simulator my project does not work correctly the problem of http connection. Someone tell where I'm wrong?

    Thank you

    Ajay.

    also to install BlackBerry JDE 5.0.

  • What is the best way to make http connection for my application can access internet on blackberry

    Hi I have crazy small application and create the regular http connection in my code.

    I m able to use internet in defining the apn but internet will not work in my application when I m using other equipment that required donot APN setting and work mobile without parameter APN there internet conection please let me know what setting that i could spend while creating the http connection so that my application work on all devices.

    Kind regards

    Navneet Gupta

    This can help you.

  • How to check if the device is configured for the HTTP connection data plan?

    Is it possible to check if the device has data during http connection (regular data plan just not bes or bis)?

    I don't want my app to make connections if it leads to an additional burden for the user by the carrier.

    lol but you can provide it as an option to the user, he should know.

  • http connection goes through the WAP gateway and not through BIS/BES

    How can I check that an http application connection passes by the WAP gateway and no BIS/BES.

    I do not have the source code of the application and need to build my own app to connect http connection made by the unit.

    I only have the jad file.

    Thank you very much for the help.

    at this point the man, you must understand a few things on your own.  Get the cod, and put the cod in the same folder as the Simulator, they will then work in the sim card.  Or you can browse to a deployment for application with the sim ota and download the cod in this way.

  • How to detect the DNS server using the device is

    Hello

    What is the means of detecting the device of a BB of DNS server uses at present, whether on wifi, plan data (cellular network), connected to a BES Server?

    Thank you

    You can probably use Network Status BPS:
    https://developer.BlackBerry.com/native/reference/core/com.QNX.doc.bps.lib_ref/topic/manual/netstatu...

Maybe you are looking for

  • How can I disable the keyboard sounds

    How can I turn off the sounds on my computer keyboard?  whenever I type a letter looks a sound ICT ICT. support it makes me crazy!

  • The experience of blue screen error after replacing the hard drive

    bought a new hd.   have windows 7 pro on the computer that goes blue screen in about 5 minutes after the start. diagnosis indicated the bad hard drive. I think I have an oem copy, key # is [Deleted by MaRoselle Cag] I was able to copy a version of wi

  • Anyone know the links for Devcon videos?

    I need to re - visit one of the devcon videos. Anyone know the links for them?

  • No button back for Playbook and Z10

    My request of WebWorks HTML5 for Playbook and Z10 occasionally open external web pages and at least in the Playbook there no back button during the display of the external web pages. How can I add a "back" button? I spent a few hours looking for solu

  • Cannot get necessary updates for windows 8.1

    Hello I'm having a problem updating Windows 8 to 8.1 Windows. I ran the 8.1 Troubleshooting and it says I need to update KB 2871389 and KB 2917499 but when I go in the settings of your laptop, it says that I have to restart my computer in order to in