Showing posts with label raw_url_encode. Show all posts
Showing posts with label raw_url_encode. Show all posts

Wednesday, September 11, 2013

HTTP RAW URL Address Encode in Java as application/x-www-form-urlencoded


package com.pritom.kumar;

import java.net.URLDecoder;
import java.net.URLEncoder;

public class RawUrlEncodeDecode {
    public static void main(String[] args) throws Exception{
        String toEncode = "a & b+c_d+e / é <p>Hello</p><?xml version='1.0'><name>Pritom K Mondal</name>";
        String encoded = URLEncoder.encode(toEncode, "UTF-8");
        System.out.println("Encoded: " + encoded);
        String decoded = URLDecoder.decode(encoded, "UTF-8");
        System.out.println("Decoded: " + decoded);
    }
}

Output

Encoded: a+%26+b%2Bc_d%2Be+%2F+%C3%A9+%3Cp%3EHello%3C%2Fp%3E%3C%3Fxml+version%3D%271.0%27%3E%3Cname%3EPritom+K+Mondal%3C%2Fname%3E

Decoded: a & b+c_d+e / é <p>Hello</p><?xml version='1.0'><name>Pritom K Mondal</name>