github.com/gogf/gf@v1.16.9/net/ghttp/internal/client/client_bytes.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package client
     8  
     9  // GetBytes sends a GET request, retrieves and returns the result content as bytes.
    10  func (c *Client) GetBytes(url string, data ...interface{}) []byte {
    11  	return c.RequestBytes("GET", url, data...)
    12  }
    13  
    14  // PutBytes sends a PUT request, retrieves and returns the result content as bytes.
    15  func (c *Client) PutBytes(url string, data ...interface{}) []byte {
    16  	return c.RequestBytes("PUT", url, data...)
    17  }
    18  
    19  // PostBytes sends a POST request, retrieves and returns the result content as bytes.
    20  func (c *Client) PostBytes(url string, data ...interface{}) []byte {
    21  	return c.RequestBytes("POST", url, data...)
    22  }
    23  
    24  // DeleteBytes sends a DELETE request, retrieves and returns the result content as bytes.
    25  func (c *Client) DeleteBytes(url string, data ...interface{}) []byte {
    26  	return c.RequestBytes("DELETE", url, data...)
    27  }
    28  
    29  // HeadBytes sends a HEAD request, retrieves and returns the result content as bytes.
    30  func (c *Client) HeadBytes(url string, data ...interface{}) []byte {
    31  	return c.RequestBytes("HEAD", url, data...)
    32  }
    33  
    34  // PatchBytes sends a PATCH request, retrieves and returns the result content as bytes.
    35  func (c *Client) PatchBytes(url string, data ...interface{}) []byte {
    36  	return c.RequestBytes("PATCH", url, data...)
    37  }
    38  
    39  // ConnectBytes sends a CONNECT request, retrieves and returns the result content as bytes.
    40  func (c *Client) ConnectBytes(url string, data ...interface{}) []byte {
    41  	return c.RequestBytes("CONNECT", url, data...)
    42  }
    43  
    44  // OptionsBytes sends a OPTIONS request, retrieves and returns the result content as bytes.
    45  func (c *Client) OptionsBytes(url string, data ...interface{}) []byte {
    46  	return c.RequestBytes("OPTIONS", url, data...)
    47  }
    48  
    49  // TraceBytes sends a TRACE request, retrieves and returns the result content as bytes.
    50  func (c *Client) TraceBytes(url string, data ...interface{}) []byte {
    51  	return c.RequestBytes("TRACE", url, data...)
    52  }
    53  
    54  // RequestBytes sends request using given HTTP method and data, retrieves returns the result
    55  // as bytes. It reads and closes the response object internally automatically.
    56  func (c *Client) RequestBytes(method string, url string, data ...interface{}) []byte {
    57  	response, err := c.DoRequest(method, url, data...)
    58  	if err != nil {
    59  		return nil
    60  	}
    61  	defer response.Close()
    62  	return response.ReadAll()
    63  }