×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    3

    Simple HTTPS Request Gone Wrong

    I've developed a frontend java midlet to collect data and send it to an already established backend. The backend takes its input via the URL eg www.backend.org/input.do?var1=x+var2=y

    Is this possible to do? Do I still have to use bitstreams if I am simple calling or "opening" a URL?

    I've tried many ways with variable rates of success. Like using http with bitstreams sent the data but then the midlet froze. This is probably a silly and simple query but please can someone help a novice J2ME programmer.

    Here is my communication to the backend (the simple non bitstream https method)

    public void run()
    {
    String urlT1 = "https://www.backend.org/input.do";
    String urlInfo = _patient.getPatientInfo(); // input variables

    String url = urlT1 + "" + urlInfo;

    try {
    // Query the server and retrieve the response.
    HttpsConnection hc = (HttpsConnection) Connector.open(url);
    hc.close();
    } catch (IOException ioe) {
    Alert a = new Alert("Exception", ioe.toString(), null, null);
    a.setTimeout(Alert.FOREVER);
    _controller.newAlert(a);
    }
    }

  2. #2
    Nokia Developer Expert
    Join Date
    Jun 2005
    Posts
    923

    Re: Simple HTTPS Request Gone Wrong

    Hi,

    In order to get your application to "call" a URL with the GET method, you need to open an InputStream, so that the HttpsConnection class will flush all buffers and perform the request. You don't need to use the InputStream's methods such as read() if there's nothing to read. Just open it and then close it.

    Daniel

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    3

    Re: Simple HTTPS Request Gone Wrong

    Thanks for the help but I'm still not having any luck sending the variables to the server and my program goes to a plain white screen once the "connection" is complete.

    Below is my updated code. Is there a difference if I use GET or POST or HEAD? I have an idea of the basic underlying difference between these methods, however none give me the desired results.

    public static String backendComms(String url) {

    HttpsConnection httpsConn = null;
    DataInputStream dis = null;
    StringBuffer messagebuffer = new StringBuffer();

    try {
    // open HTTP connection with Web server
    httpsConn = (HttpsConnection) Connector.open(url, Connector.READ_WRITE);

    // set request method to GET
    httpsConn.setRequestMethod(HttpConnection.GET);

    // retrieve the response from web Server
    dis = new DataInputStream(httpsConn.openInputStream());

    int ch;
    // Check the Content-Length first
    long len = httpsConn.getLength();
    if (len != -1) {
    for (int i = 0; i < len; i++) {
    if ((ch = dis.read()) != -1) {
    messagebuffer.append((char) ch);
    }
    }
    } else {
    // if the content-length is not available
    while ((ch = dis.read()) != -1) {
    messagebuffer.append((char) ch);
    }
    }
    dis.close();

    } catch (IOException ioe) {
    messagebuffer = new StringBuffer("ERROR!");
    } finally {
    try {
    if (httpsConn != null) httpsConn.close();
    if (dis != null) dis.close();
    } catch (IOException ignored) {}
    }
    return messagebuffer.toString();
    }

  4. #4
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    119

    Re: Simple HTTPS Request Gone Wrong

    Do not create a new dataInputStream instance but use the HttpConnection's input srteam.

    // Example
    HttpConnection hc = Connector.open( url, Connector.READ_WRITE);

    InputStream is = hc.openDataInputStream();

    // End of example.

Similar Threads

  1. how to send https request using socket example?
    By jntu_hareesh in forum Symbian Networking & Messaging (Closed)
    Replies: 9
    Last Post: 2008-10-07, 14:15
  2. get request problem using https in 6600
    By jntu_hareesh in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2004-09-21, 08:28
  3. What's going wrong with installation simple midlet (6310i)
    By zgibniew in forum Mobile Java General
    Replies: 3
    Last Post: 2003-09-24, 10:50
  4. Replies: 1
    Last Post: 2003-07-10, 07:34
  5. can someone pls send me a simple networked midlet? a newbie's request... URGENT~ Y_Y
    By lingtze1 in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2003-06-23, 08:03

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×