more fixed
Showing
1 changed file
with
12 additions
and
12 deletions
| ... | @@ -36,6 +36,7 @@ import ( | ... | @@ -36,6 +36,7 @@ import ( |
| 36 | "crypto/tls" | 36 | "crypto/tls" |
| 37 | "encoding/json" | 37 | "encoding/json" |
| 38 | "encoding/xml" | 38 | "encoding/xml" |
| 39 | "fmt" | ||
| 39 | "io" | 40 | "io" |
| 40 | "io/ioutil" | 41 | "io/ioutil" |
| 41 | "log" | 42 | "log" |
| ... | @@ -278,12 +279,15 @@ func (b *BeegoHttpRequest) JsonBody(obj interface{}) (*BeegoHttpRequest, error) | ... | @@ -278,12 +279,15 @@ func (b *BeegoHttpRequest) JsonBody(obj interface{}) (*BeegoHttpRequest, error) |
| 278 | } | 279 | } |
| 279 | 280 | ||
| 280 | func (b *BeegoHttpRequest) buildUrl(paramBody string) { | 281 | func (b *BeegoHttpRequest) buildUrl(paramBody string) { |
| 282 | if paramBody == "" { | ||
| 283 | return | ||
| 284 | } | ||
| 281 | // build GET url with query string | 285 | // build GET url with query string |
| 282 | if b.req.Method == "GET" && len(paramBody) > 0 { | 286 | if b.req.Method == "GET" { |
| 283 | if strings.Index(b.url, "?") != -1 { | 287 | if strings.Index(b.url, "?") == -1 { |
| 284 | b.url += "&" + paramBody | ||
| 285 | } else { | ||
| 286 | b.url = b.url + "?" + paramBody | 288 | b.url = b.url + "?" + paramBody |
| 289 | } else { | ||
| 290 | b.url += "&" + paramBody | ||
| 287 | } | 291 | } |
| 288 | return | 292 | return |
| 289 | } | 293 | } |
| ... | @@ -336,18 +340,14 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { | ... | @@ -336,18 +340,14 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { |
| 336 | } | 340 | } |
| 337 | var paramBody string | 341 | var paramBody string |
| 338 | if len(b.params) > 0 { | 342 | if len(b.params) > 0 { |
| 339 | var buf bytes.Buffer | ||
| 340 | for k, v := range b.params { | 343 | for k, v := range b.params { |
| 341 | buf.WriteString(url.QueryEscape(k)) | 344 | paramBody += fmt.Sprintf("&%s=%v", url.QueryEscape(k), url.QueryEscape(v)) |
| 342 | buf.WriteByte('=') | ||
| 343 | buf.WriteString(url.QueryEscape(v)) | ||
| 344 | buf.WriteByte('&') | ||
| 345 | } | 345 | } |
| 346 | paramBody = buf.String() | 346 | paramBody = paramBody[1:] |
| 347 | paramBody = paramBody[0 : len(paramBody)-1] | ||
| 348 | } | 347 | } |
| 349 | 348 | ||
| 350 | b.buildUrl(paramBody) | 349 | b.buildUrl(paramBody) |
| 350 | |||
| 351 | url, err := url.Parse(b.url) | 351 | url, err := url.Parse(b.url) |
| 352 | if err != nil { | 352 | if err != nil { |
| 353 | return nil, err | 353 | return nil, err |
| ... | @@ -399,7 +399,7 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { | ... | @@ -399,7 +399,7 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { |
| 399 | if b.setting.ShowDebug { | 399 | if b.setting.ShowDebug { |
| 400 | dump, err := httputil.DumpRequest(b.req, true) | 400 | dump, err := httputil.DumpRequest(b.req, true) |
| 401 | if err != nil { | 401 | if err != nil { |
| 402 | println(err.Error()) | 402 | log.Println(err.Error()) |
| 403 | } | 403 | } |
| 404 | b.dump = dump | 404 | b.dump = dump |
| 405 | } | 405 | } | ... | ... |
-
Please register or sign in to post a comment