|
|
@@ -26,7 +26,7 @@ func NewHttpUtil() *HttpUtil {
|
|
|
}
|
|
|
|
|
|
// 使用body post提交数据
|
|
|
-func (this *HttpUtil) PostBytes(url string, data []byte) ([]byte, error) {
|
|
|
+func (this *HttpUtil) PostBytes(url string, data []byte, headers map[string]string) ([]byte, error) {
|
|
|
|
|
|
body := bytes.NewReader(data)
|
|
|
request, err := http.NewRequest("POST", url, body)
|
|
|
@@ -34,8 +34,15 @@ func (this *HttpUtil) PostBytes(url string, data []byte) ([]byte, error) {
|
|
|
//log.Println("http.NewRequest,[err=%s][url=%s]", err, url)
|
|
|
return []byte(""), err
|
|
|
}
|
|
|
- request.Header.Set("Connection", "Keep-Alive")
|
|
|
- request.Header.Set("Content-Type", "application/json;charset=utf-8")
|
|
|
+
|
|
|
+ if headers == nil || len(headers) == 0 {
|
|
|
+ request.Header.Set("Connection", "Keep-Alive")
|
|
|
+ request.Header.Set("Content-Type", "application/json;charset=utf-8")
|
|
|
+ }else{
|
|
|
+ for k, v := range headers {
|
|
|
+ request.Header.Set(k, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return this.getResponse(request)
|
|
|
}
|