|
|
@ -5,7 +5,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
package httplib |
|
|
|
package httplib |
|
|
|
|
|
|
|
|
|
|
|
// NOTE: last sync c07b1d8 on Aug 23, 2014.
|
|
|
|
// NOTE: last sync 57e62e5 on Oct 29, 2014.
|
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"bytes" |
|
|
|
"bytes" |
|
|
@ -14,6 +14,7 @@ import ( |
|
|
|
"encoding/xml" |
|
|
|
"encoding/xml" |
|
|
|
"io" |
|
|
|
"io" |
|
|
|
"io/ioutil" |
|
|
|
"io/ioutil" |
|
|
|
|
|
|
|
"log" |
|
|
|
"mime/multipart" |
|
|
|
"mime/multipart" |
|
|
|
"net" |
|
|
|
"net" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
@ -252,35 +253,36 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
b.url = b.url + "?" + paramBody |
|
|
|
b.url = b.url + "?" + paramBody |
|
|
|
} |
|
|
|
} |
|
|
|
} else if b.req.Method == "POST" && b.req.Body == nil && len(paramBody) > 0 { |
|
|
|
} else if b.req.Method == "POST" && b.req.Body == nil { |
|
|
|
if len(b.files) > 0 { |
|
|
|
if len(b.files) > 0 { |
|
|
|
bodyBuf := &bytes.Buffer{} |
|
|
|
pr, pw := io.Pipe() |
|
|
|
bodyWriter := multipart.NewWriter(bodyBuf) |
|
|
|
bodyWriter := multipart.NewWriter(pw) |
|
|
|
for formname, filename := range b.files { |
|
|
|
go func() { |
|
|
|
fileWriter, err := bodyWriter.CreateFormFile(formname, filename) |
|
|
|
for formname, filename := range b.files { |
|
|
|
if err != nil { |
|
|
|
fileWriter, err := bodyWriter.CreateFormFile(formname, filename) |
|
|
|
return nil, err |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Fatal(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
fh, err := os.Open(filename) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Fatal(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//iocopy
|
|
|
|
|
|
|
|
_, err = io.Copy(fileWriter, fh) |
|
|
|
|
|
|
|
fh.Close() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Fatal(err) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
fh, err := os.Open(filename) |
|
|
|
for k, v := range b.params { |
|
|
|
if err != nil { |
|
|
|
bodyWriter.WriteField(k, v) |
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
//iocopy
|
|
|
|
bodyWriter.Close() |
|
|
|
_, err = io.Copy(fileWriter, fh) |
|
|
|
pw.Close() |
|
|
|
fh.Close() |
|
|
|
}() |
|
|
|
if err != nil { |
|
|
|
b.Header("Content-Type", bodyWriter.FormDataContentType()) |
|
|
|
return nil, err |
|
|
|
b.req.Body = ioutil.NopCloser(pr) |
|
|
|
} |
|
|
|
} else if len(paramBody) > 0 { |
|
|
|
} |
|
|
|
|
|
|
|
for k, v := range b.params { |
|
|
|
|
|
|
|
bodyWriter.WriteField(k, v) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
contentType := bodyWriter.FormDataContentType() |
|
|
|
|
|
|
|
bodyWriter.Close() |
|
|
|
|
|
|
|
b.Header("Content-Type", contentType) |
|
|
|
|
|
|
|
b.req.Body = ioutil.NopCloser(bodyBuf) |
|
|
|
|
|
|
|
b.req.ContentLength = int64(bodyBuf.Len()) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
b.Header("Content-Type", "application/x-www-form-urlencoded") |
|
|
|
b.Header("Content-Type", "application/x-www-form-urlencoded") |
|
|
|
b.Body(paramBody) |
|
|
|
b.Body(paramBody) |
|
|
|
} |
|
|
|
} |
|
|
@ -332,7 +334,7 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { |
|
|
|
Jar: jar, |
|
|
|
Jar: jar, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if b.setting.UserAgent != "" { |
|
|
|
if len(b.setting.UserAgent) > 0 && len(b.req.Header.Get("User-Agent")) == 0 { |
|
|
|
b.req.Header.Set("User-Agent", b.setting.UserAgent) |
|
|
|
b.req.Header.Set("User-Agent", b.setting.UserAgent) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|