×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    280

    Issue in encryption value in post method

    I am working on nokia asha sdk1.1 with using lwuit 1.5. I am using post method in my code. I am sending two parameters in post method which is in encrypted form.But my problem is that when i am getting encrypted code and use as a parameter. Then ' + ' sign in encrypted value taking as a 'space' when hit url. IN below method email and pswd are two parameters which is in encrypted form.when this method run then i get the json response which is not appropriate

    Code:
    public static void jsparsing(String email,String pswd)
        {
            System.out.println("text and pswd......"+email+"    "+pswd);
    
    
            StringBuffer result=new StringBuffer("");
            HttpConnection httpCon=null;
            System.out.println("11111111111");
            String url="http://192.168.21.118/music_app/user_confirmation";
           // String url=" http://192.168.21.118/music_app/user_confirmation";
            //String url="http://php0sunray.elasticbeanstalk.com/music_app/outlet_ads";
            InputStream ins=null;
            OutputStream ous=null;
            try{
                 //create http connection object to make requests
                System.out.println("in try block.......");
                httpCon=(HttpConnection) Connector.open(url,Connector.READ_WRITE);
                httpCon.setRequestMethod(HttpConnection.POST);
                httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                httpCon.setRequestProperty("User-Agent", "HttpMidlet/0.2");
               // httpCon.setRequestProperty("My-Custom-Property", "Requets from Kanishka");
    
                //defining POST data
               //String postdata="city="+"chandigarh"+"&id="+5;
                System.out.println("emaill..............."+email);
                System.out.println("password....1111111111.."+pswd);
                String postdata="email="+email+"&password="+pswd;
                System.out.println("postdata value is....."+postdata);
    
                //set content length
                //important : Without a content length a JSP will not process POST data
                httpCon.setRequestProperty("Content-length",String.valueOf(postdata.getBytes().length));
                //after this step any call to setResuestProperty method will raise IOException
    
                //now we have to write data to the server
                ous=httpCon.openOutputStream();
                ous.write(postdata.getBytes());
                /*ous.flush();
                ous.close();*/
    
                int response_code=httpCon.getResponseCode();
                System.out.println("response code is..."+response_code);
                System.out.println("httpresponse is..."+HttpConnection.HTTP_OK);
                if(response_code==HttpConnection.HTTP_OK)
                { //if server has a response
                    int responseLen=(int) httpCon.getLength();
                    System.out.println(responseLen);
                    ins=httpCon.openInputStream();
                    if(ins==null){
                        result.append("Cannot open server response!");
                    }
    
    //                if(responseLen>0){
    //                    int chr;
    //                    while((chr=ins.read())!=-1){
    //                        result.append((char)chr);
    //                    }
    //                }
                    byte[] respData=new byte[responseLen];
                    ins.read(respData);
                    String tmp=new String(respData);
                    result.append(tmp);
                    System.out.println("hiiiiii..............");
                    System.out.println("value of reslult is..."+result);
    
                }
                else
                {
                    System.out.println("else block..............");
                    int responseLen=(int) httpCon.getLength();
    
                System.out.println("value of responselen is ..."+responseLen);
                ins=httpCon.openInputStream();
                if(ins==null){
                    result.append("Cannot open server response!");
                }
    
    //            if(responseLen>0){
    //                int chr;
    //                while((chr=ins.read())!=-1){
    //                    result.append((char)chr);
    //                }
    //            }
                byte[] respData=new byte[responseLen];
                ins.read(respData);
                String tmp=new String(respData);
                result.append(tmp);
                System.out.println("hiiiiii..............");
                System.out.println("value of reslult is..."+result);
    
                }
            }
            catch(IOException e)
            {
                result.append("Network Problem : " + e.getMessage());
                System.out.println("exception....in try jsparsing"+e);
            }
            finally
            {
                if(ins!=null){
                    try {
                         ous.flush();
                         ous.close();
    
                        ins.close();
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                }
                if(ous!=null){
                    try {
                        ous.close();
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                }
                System.out.println("Connection closed!");
            }
            System.out.println("JSON RESPONSE IS..."+"\n"+result.toString());
            System.out.println("the  JSON PARSING TO BE CONTINOU........");
            try
            {
            JSONArray jsarray=new JSONArray(result.toString());
            System.out.println("value of jsarray is .."+jsarray.length());
    
    
    
            }
            catch(Exception e)
            {
                System.out.println("reading json parsing...."+e.toString());
            }
        }

    Please Help

  2. #2
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    686

    Re: Issue in encryption value in post method

    @Manpreet_Singh: I'm sorry but your message is almost unreadable and I cannot exactly understand what is it that your saying...
    I don't see in your code any sign of encryption at all and I think you might be confusing encryption with URL encoding which are two separate things.
    With URL encoding the space char ' ' is converted to '+' as part of the specification.
    If you are facing problems in the server side then I suggest you need to URL decode the post data in the server before trying to read it.
    Heard of DVLUP? Join here

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,750

    Re: Issue in encryption value in post method

    Indeed, you are using application/x-www-form-urlencoded content type, which has some rules. Replacing spaces with + is just one of them. http://developer.nokia.com/community...URL_in_Java_ME shows some more.
    Anyway, if your server side is Java, URLDecoder is the class which you may want to use. PHP also has some urldecode function.

Similar Threads

  1. Separates encryption and decryption only one This method
    By mohamed2011 in forum Mobile Java Networking & Messaging & Security
    Replies: 4
    Last Post: 2011-03-18, 07:37
  2. This is the right method to use POST?
    By gardner_xu in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2009-04-08, 06:52
  3. activation key expired-Encryption method:AES128CBC
    By b_anand in forum Digital Rights Management & Content Downloading
    Replies: 1
    Last Post: 2008-04-05, 08:19
  4. Forward-Lock encryption method with 3650
    By pituvaca in forum Digital Rights Management & Content Downloading
    Replies: 0
    Last Post: 2003-05-19, 15:15

Posting Permissions

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