Commit 51161361 authored by JessonChan's avatar JessonChan Committed by astaxie

more fixed

parent 6da0cdb9
...@@ -36,6 +36,7 @@ import ( ...@@ -36,6 +36,7 @@ import (
"crypto/tls" "crypto/tls"
"encoding/json" "encoding/json"
"encoding/xml" "encoding/xml"
"fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"log" "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)
} }
func (b *BeegoHttpRequest) buildUrl(paramBody string) { func (b *BeegoHttpRequest) buildUrl(paramBody string) {
if paramBody == "" {
return
}
// build GET url with query string // build GET url with query string
if b.req.Method == "GET" && len(paramBody) > 0 { if b.req.Method == "GET" {
if strings.Index(b.url, "?") != -1 { if strings.Index(b.url, "?") == -1 {
b.url += "&" + paramBody
} else {
b.url = b.url + "?" + paramBody b.url = b.url + "?" + paramBody
} else {
b.url += "&" + paramBody
} }
return return
} }
...@@ -336,18 +340,14 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { ...@@ -336,18 +340,14 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) {
} }
var paramBody string var paramBody string
if len(b.params) > 0 { if len(b.params) > 0 {
var buf bytes.Buffer
for k, v := range b.params { for k, v := range b.params {
buf.WriteString(url.QueryEscape(k)) paramBody += fmt.Sprintf("&%s=%v", url.QueryEscape(k), url.QueryEscape(v))
buf.WriteByte('=')
buf.WriteString(url.QueryEscape(v))
buf.WriteByte('&')
} }
paramBody = buf.String() paramBody = paramBody[1:]
paramBody = paramBody[0 : len(paramBody)-1]
} }
b.buildUrl(paramBody) b.buildUrl(paramBody)
url, err := url.Parse(b.url) url, err := url.Parse(b.url)
if err != nil { if err != nil {
return nil, err 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) {
if b.setting.ShowDebug { if b.setting.ShowDebug {
dump, err := httputil.DumpRequest(b.req, true) dump, err := httputil.DumpRequest(b.req, true)
if err != nil { if err != nil {
println(err.Error()) log.Println(err.Error())
} }
b.dump = dump b.dump = dump
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment