Closed ghost closed 8 years ago
如果使用默认的client来进行并发的请求,需要调用Begin方法:
go func() {
httpclient.
Begin().
WithHeader("Req-A", "a").
Get("http://google.com")
}()
go func() {
httpclient.
Begin().
WithHeader("Req-B", "b").
Get("http://google.com")
}()
我靠 回复的这么及时!
panic: runtime error: invalid memory address or nil pointer dereference [signal 0xb code=0x1 addr=0x38 pc=0x8c76e]
goroutine 2607 [running]: panic(0x376ba0, 0xc82000a0e0) /**_runtime/panic.go:481 +0x3e6 httpclient.(_Response).ReadAll(0xc820028128, 0x0, 0x0, 0x0, 0x0, 0x0)
我替你验证了 依然出错。
是不是没有检测请求是否成功就直接读取了?能贴出完整代码不?
我不读取的。, := httpclient.NewHttpClient().Begin().WithHeader("Accept-Language", "en-us;q=1").WithHeader("Authorization","123123").Post(dataUrl, nil)
package main
import (
"fmt"
"github.com/ddliu/go-httpclient"
"time"
)
func main() {
go func() {
dataUrl := "http://www.baidu.com"
res, err := httpclient.NewHttpClient().Begin().WithHeader("Accept-Language", "en-us;q=1").WithHeader("Authorization","123123").Post(dataUrl, nil)
fmt.Println(res.Status, err)
}()
go func() {
dataUrl := "http://www.baidu.com"
res, err := httpclient.NewHttpClient().Begin().WithHeader("Accept-Language", "en-us;q=1").WithHeader("Authorization","123123").Post(dataUrl, nil)
fmt.Println(res.Status, err)
}()
time.Sleep(3 * time.Second)
}
结果:
$ go run test.go
200 OK <nil>
200 OK <nil>
我知道什么问题了 是因为mac 系统的原因。
go function testPostUrl(); 当你的HTTP 来测试go 的一直httpcleint 请求的时候 。 就呵呵了!