ghttp_client_content.go 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2017 gf Author(https://github.com/gogf/gf). 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. package ghttp
  7. // GetContent is a convenience method for sending GET request, which retrieves and returns
  8. // the result content and automatically closes response object.
  9. func (c *Client) GetContent(url string, data ...interface{}) string {
  10. return string(c.RequestBytes("GET", url, data...))
  11. }
  12. // PutContent is a convenience method for sending PUT request, which retrieves and returns
  13. // the result content and automatically closes response object.
  14. func (c *Client) PutContent(url string, data ...interface{}) string {
  15. return string(c.RequestBytes("PUT", url, data...))
  16. }
  17. // PostContent is a convenience method for sending POST request, which retrieves and returns
  18. // the result content and automatically closes response object.
  19. func (c *Client) PostContent(url string, data ...interface{}) string {
  20. return string(c.RequestBytes("POST", url, data...))
  21. }
  22. // DeleteContent is a convenience method for sending DELETE request, which retrieves and returns
  23. // the result content and automatically closes response object.
  24. func (c *Client) DeleteContent(url string, data ...interface{}) string {
  25. return string(c.RequestBytes("DELETE", url, data...))
  26. }
  27. // HeadContent is a convenience method for sending HEAD request, which retrieves and returns
  28. // the result content and automatically closes response object.
  29. func (c *Client) HeadContent(url string, data ...interface{}) string {
  30. return string(c.RequestBytes("HEAD", url, data...))
  31. }
  32. // PatchContent is a convenience method for sending PATCH request, which retrieves and returns
  33. // the result content and automatically closes response object.
  34. func (c *Client) PatchContent(url string, data ...interface{}) string {
  35. return string(c.RequestBytes("PATCH", url, data...))
  36. }
  37. // ConnectContent is a convenience method for sending CONNECT request, which retrieves and returns
  38. // the result content and automatically closes response object.
  39. func (c *Client) ConnectContent(url string, data ...interface{}) string {
  40. return string(c.RequestBytes("CONNECT", url, data...))
  41. }
  42. // OptionsContent is a convenience method for sending OPTIONS request, which retrieves and returns
  43. // the result content and automatically closes response object.
  44. func (c *Client) OptionsContent(url string, data ...interface{}) string {
  45. return string(c.RequestBytes("OPTIONS", url, data...))
  46. }
  47. // TraceContent is a convenience method for sending TRACE request, which retrieves and returns
  48. // the result content and automatically closes response object.
  49. func (c *Client) TraceContent(url string, data ...interface{}) string {
  50. return string(c.RequestBytes("TRACE", url, data...))
  51. }
  52. // RequestContent is a convenience method for sending custom http method request, which
  53. // retrieves and returns the result content and automatically closes response object.
  54. func (c *Client) RequestContent(method string, url string, data ...interface{}) string {
  55. return string(c.RequestBytes(method, url, data...))
  56. }