使用 Goland 作为 Http Client 时有很多方法,基本上都是使用 net/http
这个包来进行相关的实现。
func NewRequest(method, url string, body io.Reader) (*Request, error)
这个函数有三个参数,
method :请求方法法;
url:请求URL
body:可选参数,按照函数内部相关代码可以看出,这个参数的值作为请求body给带进去了。
rc, ok := body.(io.ReadCloser)
if !ok && body != nil {
rc = ioutil.NopCloser(body)
}
// The host's colon:port should be normalized. See Issue 14836.
u.Host = removeEmptyPort(u.Host)
req := &Request{
Method: method,
URL: u,
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
Header: make(Header),
Body: rc, //主要就是看这里,将上面的body带入这里。
Host: u.Host,
}