2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2019-07-25 21:01:04 +08:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
|
|
|
|
package ghttp
|
|
|
|
|
2019-12-19 15:14:05 +08:00
|
|
|
// GetBytes sends a GET request, retrieves and returns the result content as bytes.
|
2019-07-25 21:01:04 +08:00
|
|
|
func (c *Client) GetBytes(url string, data ...interface{}) []byte {
|
|
|
|
return c.RequestBytes("GET", url, data...)
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:14:05 +08:00
|
|
|
// PutBytes sends a PUT request, retrieves and returns the result content as bytes.
|
2019-07-25 21:01:04 +08:00
|
|
|
func (c *Client) PutBytes(url string, data ...interface{}) []byte {
|
|
|
|
return c.RequestBytes("PUT", url, data...)
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:14:05 +08:00
|
|
|
// PostBytes sends a POST request, retrieves and returns the result content as bytes.
|
2019-07-25 21:01:04 +08:00
|
|
|
func (c *Client) PostBytes(url string, data ...interface{}) []byte {
|
|
|
|
return c.RequestBytes("POST", url, data...)
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:14:05 +08:00
|
|
|
// DeleteBytes sends a DELETE request, retrieves and returns the result content as bytes.
|
2019-07-25 21:01:04 +08:00
|
|
|
func (c *Client) DeleteBytes(url string, data ...interface{}) []byte {
|
|
|
|
return c.RequestBytes("DELETE", url, data...)
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:14:05 +08:00
|
|
|
// HeadBytes sends a HEAD request, retrieves and returns the result content as bytes.
|
2019-07-25 21:01:04 +08:00
|
|
|
func (c *Client) HeadBytes(url string, data ...interface{}) []byte {
|
|
|
|
return c.RequestBytes("HEAD", url, data...)
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:14:05 +08:00
|
|
|
// PatchBytes sends a PATCH request, retrieves and returns the result content as bytes.
|
2019-07-25 21:01:04 +08:00
|
|
|
func (c *Client) PatchBytes(url string, data ...interface{}) []byte {
|
|
|
|
return c.RequestBytes("PATCH", url, data...)
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:14:05 +08:00
|
|
|
// ConnectBytes sends a CONNECT request, retrieves and returns the result content as bytes.
|
2019-07-25 21:01:04 +08:00
|
|
|
func (c *Client) ConnectBytes(url string, data ...interface{}) []byte {
|
|
|
|
return c.RequestBytes("CONNECT", url, data...)
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:14:05 +08:00
|
|
|
// OptionsBytes sends a OPTIONS request, retrieves and returns the result content as bytes.
|
2019-07-25 21:01:04 +08:00
|
|
|
func (c *Client) OptionsBytes(url string, data ...interface{}) []byte {
|
|
|
|
return c.RequestBytes("OPTIONS", url, data...)
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:14:05 +08:00
|
|
|
// TraceBytes sends a TRACE request, retrieves and returns the result content as bytes.
|
2019-07-25 21:01:04 +08:00
|
|
|
func (c *Client) TraceBytes(url string, data ...interface{}) []byte {
|
|
|
|
return c.RequestBytes("TRACE", url, data...)
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:14:05 +08:00
|
|
|
// RequestBytes sends request using given HTTP method and data, retrieves returns the result
|
|
|
|
// as bytes. It reads and closes the response object internally automatically.
|
2019-07-25 21:01:04 +08:00
|
|
|
func (c *Client) RequestBytes(method string, url string, data ...interface{}) []byte {
|
|
|
|
response, err := c.DoRequest(method, url, data...)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
defer response.Close()
|
|
|
|
return response.ReadAll()
|
|
|
|
}
|