How can I encode a URL String?


You can work with the OOP statements using the Java class named "java.net.URLEncoder", available with the Java Runtime, useful to encode a URL string: http://docs.oracle.com/javase/7/docs/api/java/net/URLEncoder.html

The following is an example of a COBOL program that encodes a string using UTF-8 as the encoding scheme:

program-id. pencode.
configuration section.
repository.
 class jencoder as "java.net.URLEncoder"
 class jstring as "java.lang.String"
 class jencodeEx as "java.io.UnsupportedEncodingException"
 .

working-storage section.
77 w-jencoder object reference jencoder.
77 w-string object reference jstring.
77 var pic x any length.

procedure division.
main.
 try
    set w-string to jstring:>new("The string ü@#foo-bar")
    set var to jencoder:>encode(w-string, "UTF-8")
    display var
 catch jencodeEx
  display exception-object
 end-try.
 stop run.



Article ID: 211
Created: October 25, 2013
Last Updated: April 15, 2024
Author: Support KB Author

Online URL: https://support.veryant.com/support/phpkb/article.php?id=211