Skip to content

Instantly share code, notes, and snippets.

@Houserqu
Created May 5, 2021 01:54
Show Gist options
  • Save Houserqu/eff2f787411089baf62ad61c3dcbd64f to your computer and use it in GitHub Desktop.
Save Houserqu/eff2f787411089baf62ad61c3dcbd64f to your computer and use it in GitHub Desktop.
UrlEncode

encodeURIComponent()

function RFC3986UrlEncode(str){
  return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
    return '%' + c.charCodeAt(0).toString(16).toUpperCase();
  });
}
// 在 java 等语言中,有些进行的是 HTML4 编码,空格转换成 + 号,而 js 转换成 %20
function javaSdkUrlEncode(str) {
  return encodeURIComponent(str).replace(/%20/g,'+')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment