Encode / decode URLs

后端 未结 8 1505
攒了一身酷
攒了一身酷 2020-11-28 03:46

What\'s the recommended way of encoding and decoding entire URLs in Go? I am aware of the methods url.QueryEscape and url.QueryUnescape, but they d

8条回答
  •  無奈伤痛
    2020-11-28 04:32

    Hope this helps

     // url encoded
    func UrlEncodedISO(str string) (string, error) {
        u, err := url.Parse(str)
        if err != nil {
            return "", err
        }
        q := u.Query()
        return q.Encode(), nil
    }
    
     * encoded into %2A
     # encoded into %23
     % encoded into %25
     < encoded into %3C
     > encoded into %3E
     + encoded into %2B
     enter key (#13#10) is encoded into %0D%0A
    

提交回复
热议问题