UrlEncode fix for input strings > 32766 limit

Initial code by @jeffthieleke-wf with my additions of null parameter
check, correct maxLength of 32766, and matching indentations per
@Haacked.