×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    1

    Http Connection sending another request after 30 sec in s40 series

    I'm writing one application in which I'm sending post request to server. The problem is that Nokia S40 series phone sends 2 request if it doesn't get response within 30 sec. I have checked the same with s60 series phone in my app is working fine.

    One solution I found is to start timer while opening connection and terminate the connection after 25sec if connection not getting response. But it is also worthless. Here I'm attaching my code. Please review it and help me if possible.

    try
    {

    param="function=CloseRecharge&LoginId="+SharedVariable.getUserInfo().getLoginID()
    +"&BatchId="+SharedVariable.getSelectedProduct().getBatchID()
    +"&SystemServiceID="+SharedVariable.getSelectedProduct().getSystemServiceID()
    +"&ReferalNumber="+strMobileNo
    +"&FromANI="+fromMoNo
    +"&Email="+""
    +"&Checksum="+Checksum;

    connection = (HttpConnection) Connector.open(url);

    timeout=0;
    t.schedule(new TimerTask()
    {
    public void run()
    {
    try
    {
    timeout+=1;
    System.out.println("Timeout value:"+timeout);

    if(timeout>=25)
    {
    //timeout every 1 munite
    timeout=0;
    System.out.print("Connection is closing");

    connection.close();
    connection=null;
    if(is!=null)
    is.close();

    Alert alert=new Alert("HttpConn Closed", "connection closed",null, AlertType.WARNING);
    alert.setTimeout(Alert.FOREVER);

    display.setCurrent(alert,new MainMenu("Menu", parent));
    this.cancel();

    }
    }
    catch(Exception e)
    {
    System.out.println("========Exception occured in Timer Task");
    e.printStackTrace();
    }
    }
    }
    , 0, 1000);

    connection.setRequestMethod(HttpConnection.POST);
    connection.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0");
    connection.setRequestProperty("Accept_Language","en-US");
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    connection.setRequestProperty("Content-length", ""+param.getBytes().length);
    out = connection.openOutputStream();
    out.write(param.getBytes());
    out.flush();
    param=null;
    if (connection.getResponseCode() == HttpConnection.HTTP_OK )
    {
    t.cancel();
    int len = (int)connection.getLength();
    InputStream istrm = connection.openInputStream();
    if (istrm == null)
    {
    throw new IOException("Cannot open HTTP InputStream, aborting");
    }
    if (len != -1)
    {
    data = new byte[len];
    int bytesRead = istrm.read(data);
    }
    else
    {
    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    int ch;
    int count = 0;

    while ((ch = istrm.read()) != -1)
    {
    bo.write(ch);
    count++;
    }
    data = bo.toByteArray();
    bo.close();
    }
    String response = new String(data);
    displayResponse();
    }//if
    else
    {
    Alert error=new Alert("ResponseCode:"+connection.getResponseCode(),
    null,
    null,AlertType.INFO);
    error.setTimeout(Alert.FOREVER);
    display.setCurrent(error,new MainMenu("Menu", parent));
    }
    catch(Exception exception)
    {
    displayErrorMessage(exception);
    }
    finally
    {
    try
    {
    if(connection!=null)
    connection.close();
    if(is!=null)
    is.close();
    }
    catch (IOException ex)
    {
    System.out.println("Exception in Finally block....");
    ex.printStackTrace();
    }
    }

  2. #2
    Registered User
    Join Date
    Feb 2012
    Posts
    3

    Re: Http Connection sending another request after 30 sec in s40 series

    please help me

Similar Threads

  1. HTTP Connection sending request twice after 30 sec
    By nrv124u in forum Mobile Java General
    Replies: 8
    Last Post: 2012-12-01, 10:19
  2. Sending multiple http get request
    By dev_Cis in forum Symbian Networking & Messaging (Closed)
    Replies: 7
    Last Post: 2011-12-16, 06:48
  3. S40 Phones sending HTTP request twice
    By gaurav007 in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2010-01-04, 12:11
  4. Sending HTTP GET request with body
    By moldovan_catalin in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2009-01-13, 18:49
  5. problem sending an http request with # in it.
    By jaazz in forum Mobile Java Networking & Messaging & Security
    Replies: 4
    Last Post: 2006-12-06, 10:58

Posting Permissions

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