×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    35

    Error Sending data to Server

    hi guys,
    I want to send data to server by Get method. But my following code does not send data but return response code 200. If I supply wrong url then it throws exception.

    Code:
    import javax.microedition.io.Connector;
    import javax.microedition.io.HttpConnection;
    
    /**
     *
     * @author Administrator
     */
    public class SendComment implements Runnable {
    
        String strComment;
        PlayerUI playerUI;
    
        /**
         *  Set the Comment
         * @param strComment
         */
        public void setStrComment( String strComment ){
            this.strComment = strComment;
            this.playerUI = playerUI;
        }
    
        /**
         * Return the comment string
         * @return strComment
         */
        public String getStrComment(){
            if(this.strComment == null){
                this.strComment = "";
            }
    
            return this.strComment.replace(' ', '%');
        }
    
        public void run() {
          
            String url = "http://localhost/index.php?data="+getStrComment();
            HttpConnection http = null;
    
            try {
                // Create the connection
                http = (HttpConnection) Connector.open(url, Connector.READ_WRITE, false);
    
                //----------------
                // Client Request
                //----------------
                // 1) Send request method
                http.setRequestMethod(HttpConnection.GET);
    
                // 2) Send header information (this header is optional)
                http.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.1");
                http.setRequestProperty("Connection", "close");
                // Get header information
                System.out.println("responce code"+http.getResponseCode());
            } catch (Exception e) {
                System.out.println("Error sending to sever");
                // Nothing
            }finally{
                // Update the main screen
               
                try{
                if(http != null){
                    http.close();
                }
                }catch( Exception e){
                    // Nothing
                }
            }
            
        }
    }
    If I debug the cod then it will step in all line and end with no error.But I will not display any alert to access network and also doesn't send data.
    Where is the problem?
    Thx in advance

  2. #2
    Nokia Developer Champion
    Join Date
    Sep 2007
    Posts
    915

    Re: Error Sending data to Server

    Quote Originally Posted by mramin05 View Post
    hi guys,
    I want to send data to server by Get method. But my following code does not send data but return response code 200. If I supply wrong url then it throws exception.

    Code:
    import javax.microedition.io.Connector;
    import javax.microedition.io.HttpConnection;
    
    /**
     *
     * @author Administrator
     */
    public class SendComment implements Runnable {
    
        String strComment;
        PlayerUI playerUI;
    
        /**
         *  Set the Comment
         * @param strComment
         */
        public void setStrComment( String strComment ){
            this.strComment = strComment;
            this.playerUI = playerUI;
        }
    
        /**
         * Return the comment string
         * @return strComment
         */
        public String getStrComment(){
            if(this.strComment == null){
                this.strComment = "";
            }
    
            return this.strComment.replace(' ', '%');
        }
    
        public void run() {
          
            String url = "http://localhost/index.php?data="+getStrComment();
            HttpConnection http = null;
    
            try {
                // Create the connection
                http = (HttpConnection) Connector.open(url, Connector.READ_WRITE, false);
    
                //----------------
                // Client Request
                //----------------
                // 1) Send request method
                http.setRequestMethod(HttpConnection.GET);
    
                // 2) Send header information (this header is optional)
                http.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.1");
                http.setRequestProperty("Connection", "close");
                // Get header information
                System.out.println("responce code"+http.getResponseCode());
            } catch (Exception e) {
                System.out.println("Error sending to sever");
                // Nothing
            }finally{
                // Update the main screen
               
                try{
                if(http != null){
                    http.close();
                }
                }catch( Exception e){
                    // Nothing
                }
            }
            
        }
    }
    If I debug the cod then it will step in all line and end with no error.But I will not display any alert to access network and also doesn't send data.
    Where is the problem?
    Thx in advance
    If there is space and any special character in the data which you are passing then you need to encode it.

  3. #3
    Regular Contributor
    Join Date
    Dec 2007
    Posts
    159

    Re: Error Sending data to Server

    hey i think problem in this line
    return this.strComment.replace(' ', '%');
    because you are using % for encode space but the space should be encoded as %20 in the url.
    so please check it.

Similar Threads

  1. Replies: 8
    Last Post: 2009-06-25, 18:28
  2. How to handle UI, server connection and file handling in MIDP application for 6630?
    By SanjayKhuntia in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2008-09-19, 08:36
  3. Replies: 3
    Last Post: 2008-09-09, 04:53
  4. How to send mobile file data to Server on Nokia 6630?
    By SanjayKhuntia in forum Symbian
    Replies: 1
    Last Post: 2008-08-25, 11:26
  5. GPRS connection problems on 6600..
    By suckho in forum Symbian Networking & Messaging (Closed)
    Replies: 10
    Last Post: 2005-12-02, 14:00

Posting Permissions

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