添加urlencode

This commit is contained in:
aozhiwei 2021-08-12 13:41:05 +08:00
parent 562242ca3f
commit d82df9df79
2 changed files with 15 additions and 0 deletions

View File

@ -30,6 +30,7 @@ func HttpGetEx(url string, params *XObject,
if !StrContains(url, "?") { if !StrContains(url, "?") {
url = url + "?" url = url + "?"
} }
url = url + params.ToUrlEncodedStr()
client := &http.Client{} client := &http.Client{}
request, err := http.NewRequest("GET", url, nil) request, err := http.NewRequest("GET", url, nil)
if err != nil { if err != nil {

View File

@ -1,6 +1,7 @@
package q5 package q5
import ( import (
"net/url"
"encoding/json" "encoding/json"
) )
@ -171,6 +172,19 @@ func (this *XObject) ToJsonStr() string {
} }
} }
func (this *XObject) ToUrlEncodedStr() string {
if this.IsObject() {
u := url.Values{}
kvObj := this._val.(map[string]*XObject)
for key, val := range kvObj {
u.Set(key, val.AsXValue().GetString())
}
return u.Encode()
} else {
return ""
}
}
func (this *XObject) ToInterface() interface{} { func (this *XObject) ToInterface() interface{} {
if this._type == XOT_ARRAY { if this._type == XOT_ARRAY {
array := this._val.([]*XObject) array := this._val.([]*XObject)