×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    2

    Http connection problems

    I made J2ME application using http conenction to get a data from webserver. It works really good on emulator but Nokia 7650 doenst connect to webserver through http protocol.

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    26
    I suppose your firmware is below 4.39 (a few HTTP bugs were fixed in this firmware). (firmware can be seen by typing *#0000#
    1) You may try connecting with a seperate thread
    2) Redirect your get to post at the server side (HTTP Post from older firmwares comes as a Get)

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    12
    Hi,
    I have a nokia 7210 withFirmware version 3.09
    02-10-02
    NHL-4

    (In short pretty old)

    I am trying to make an HTTP Post connection which is failing onthe phone. I guess i will have to change my code to do a HTTP Get.

    Does any body have an idea how do i update the Firmware version on my phone
    And what is the max limit of bytes i can send using HTTP Get method.

    Thanks
    Harpreet

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    26
    firmware upgrade can be done at any nokia customer care center.

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    33
    Switching to GET is generally a bad idea.
    The Nokia bug coefficient for GET is even hgher than for POST.

    I've seen various reports about the limit of a GET on different Nokia devices, but imho none of these reports are authoritative and many of the problems were fixed by coincidence.

    In your case the problem is almost certainly someplace other than the fact you are doing a POST. eg. are you correctly setting the Content-Length http header ?

  6. #6
    Registered User
    Join Date
    Jun 2003
    Posts
    12
    I have tried making an normal HTTP get connection this works.
    However during Http post, i write data over Outstream and when i try to make an Inputstream it fails, gives an null pointer exception. This works on the emulator but not on the phone.

    The code I am using is attached below, could someone plz go thru it point out what i am doing wrong. (Suggestion to nokia people plz allow to send attachments, this post looks bad with the code.)

    public class SimpleHTTP extends MIDlet implements CommandListener
    {
    Display display;
    Form form;
    int iNoofMaxTries;
    private HttpConnection myConn;
    private OutputStream OutStream;
    public static final byte[] login_Request = { (byte) 0x03, (byte) 0x01, (byte) 0x6A, (byte) 0x00, (byte) 0xC9, (byte) 0x05, (byte) 0x03, (byte) 0x31};
    int attempt;
    String url;
    public void startApp()
    {

    form = new Form("Hello");
    display.setCurrent(form);
    //readContents("Hello");
    sendMsgtoServer(login_Request);

    }

    protected void pauseApp(){}

    protected void destroyApp(boolean test)
    {
    }

    public SimpleHTTP()
    {
    display = Display.getDisplay(this);
    iNoofMaxTries = 2;
    attempt= 0;
    url ="http://www.hotmail.com";
    }

    public void sendMsgtoServer(byte[] p_bMsgtoSend)
    {
    int sTries = 0;
    boolean bResult = false;
    do
    {
    openHttpConnection(p_bMsgtoSend.length);
    form.append("Opened Connection");
    bResult = sendMsgoverSocket(p_bMsgtoSend);

    if (bResult)
    break;
    else
    sTries = sTries + 1;
    }while (sTries < this.iNoofMaxTries);


    }

    public void openHttpConnection(int iLengthofMsg)
    {
    StringBuffer sbfURL = new StringBuffer("http://");
    sbfURL.append("www.hotmail.com");
    sbfURL.append(":");
    sbfURL.append(8080);
    sbfURL.append("/");
    sbfURL.append("");
    try
    {
    myConn = (HttpConnection)Connector.open(sbfURL.toString());
    setHttpHeaders(iLengthofMsg);
    OutStream = myConn.openOutputStream();
    }
    catch (IOException ioe)
    {
    System.out.println("IOException in openHttpConnection");
    }
    url = sbfURL.toString();
    }

    /*
    * If the connection is not closed it would close it and set it to null.
    */
    public void closeConnection()
    {
    try
    {
    if( OutStream != null )
    {
    OutStream.close();
    OutStream = null;
    }
    if( myConn != null )
    {
    myConn.close();
    myConn = null;
    }
    }
    catch (IOException IOE)
    {
    System.out.println("IO Exception while closing chonnection");
    }
    }

    private boolean sendMsgoverSocket(byte[] p_MsgtoSend)
    {
    boolean bCheckifHTTPCorrect = false;
    int iHttpResponseCode = 0;
    int iResponselength = 0;
    InputStream InStream;
    byte[] data;
    byte[] Newdata;
    if(myConn != null && OutStream != null)
    {
    try
    {

    OutStream.write(p_MsgtoSend);
    form.append("data written ");
    OutStream.flush();

    //form.append(" "+myConn.getResponseCode());
    form.append("data written ");
    OutStream.close();
    OutStream = null;
    myConn.close();
    myConn = null;
    HttpConnection myConn1 = (HttpConnection)Connector.open(url);
    InStream = myConn1.openInputStream();
    form.append("Opened inputstream");
    // Get the length and process the data
    //iResponselength = (int)myConn.getLength();
    iResponselength = 100;
    data = new byte[iResponselength];
    InStream.read(data)
    }
    catch(IOException IOE)
    {
    form.append(IOE.getMessage());
    System.out.println("Error while sending data " +IOE.getMessage());
    }
    }//end of if

    return false;
    }// End of SendMsgoverSocket()



    /*
    * This function would set the HTTP headers required for sending out data.
    */

    public void setHttpHeaders(int iLengthofMsg)
    {
    if( null == myConn )
    return;
    try
    {
    // Set the request headers
    myConn.setRequestMethod(HttpConnection.POST);

    myConn.setRequestProperty("Accept-Language", "en-us");
    myConn.setRequestProperty("Content-Language", "no-cache");
    myConn.setRequestProperty("Host", "localhost:8090");
    myConn.setRequestProperty("Content-Type", "application/vnd.wv.csp.wbxml");
    myConn.setRequestProperty("Cache-Control", "no-cache");
    myConn.setRequestProperty("Connection", "Keep-Alive");
    myConn.setRequestProperty("Proxy-Connection", "Keep-Alive");
    myConn.setRequestProperty("Content-Length",String.valueOf(iLengthofMsg));
    }

    catch (IOException ioe)
    {
    System.out.println("Exception !!!");
    }

    }

    public void commandAction(Command com, Displayable disp)
    {
    }

    }

Posting Permissions

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