URL Encode and Decode Special character in Java

前端 未结 4 1914
清酒与你
清酒与你 2020-12-29 07:19

In Java, I need to use HTTP Post to send request to server, but if in the parameter of the URL contains some special character it throws below Exception

4条回答
  •  滥情空心
    2020-12-29 07:57

    To encode text for safe passage through the internets:

    import java.net.*;
    ...
    try {
        encodedValue= URLEncoder.encode(rawValue, "UTF-8");
    } catch (UnsupportedEncodingException uee) { }
    

    And to decode:

    try {
        decodedValue = URLDecoder.decode(rawValue, "UTF-8");
    } catch (UnsupportedEncodingException uee) { }
    

提交回复
热议问题