class_httprequest.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the HTTPRequest.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_HTTPRequest:
  6. HTTPRequest
  7. ===========
  8. **Inherits:** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. **Category:** Core
  10. Brief Description
  11. -----------------
  12. A node with the ability to send HTTP requests.
  13. Properties
  14. ----------
  15. +-----------------------------+--------------------------------------------------------------------+-------+
  16. | :ref:`int<class_int>` | :ref:`body_size_limit<class_HTTPRequest_property_body_size_limit>` | -1 |
  17. +-----------------------------+--------------------------------------------------------------------+-------+
  18. | :ref:`String<class_String>` | :ref:`download_file<class_HTTPRequest_property_download_file>` | "" |
  19. +-----------------------------+--------------------------------------------------------------------+-------+
  20. | :ref:`int<class_int>` | :ref:`max_redirects<class_HTTPRequest_property_max_redirects>` | 8 |
  21. +-----------------------------+--------------------------------------------------------------------+-------+
  22. | :ref:`int<class_int>` | :ref:`timeout<class_HTTPRequest_property_timeout>` | 0 |
  23. +-----------------------------+--------------------------------------------------------------------+-------+
  24. | :ref:`bool<class_bool>` | :ref:`use_threads<class_HTTPRequest_property_use_threads>` | false |
  25. +-----------------------------+--------------------------------------------------------------------+-------+
  26. Methods
  27. -------
  28. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | void | :ref:`cancel_request<class_HTTPRequest_method_cancel_request>` **(** **)** |
  30. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`int<class_int>` | :ref:`get_body_size<class_HTTPRequest_method_get_body_size>` **(** **)** const |
  32. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`int<class_int>` | :ref:`get_downloaded_bytes<class_HTTPRequest_method_get_downloaded_bytes>` **(** **)** const |
  34. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`Status<enum_HTTPClient_Status>` | :ref:`get_http_client_status<class_HTTPRequest_method_get_http_client_status>` **(** **)** const |
  36. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`request<class_HTTPRequest_method_request>` **(** :ref:`String<class_String>` url, :ref:`PoolStringArray<class_PoolStringArray>` custom_headers=PoolStringArray( ), :ref:`bool<class_bool>` ssl_validate_domain=true, :ref:`Method<enum_HTTPClient_Method>` method=0, :ref:`String<class_String>` request_data="" **)** |
  38. +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. Signals
  40. -------
  41. .. _class_HTTPRequest_signal_request_completed:
  42. - **request_completed** **(** :ref:`int<class_int>` result, :ref:`int<class_int>` response_code, :ref:`PoolStringArray<class_PoolStringArray>` headers, :ref:`PoolByteArray<class_PoolByteArray>` body **)**
  43. Emitted when a request is completed.
  44. Enumerations
  45. ------------
  46. .. _enum_HTTPRequest_Result:
  47. .. _class_HTTPRequest_constant_RESULT_SUCCESS:
  48. .. _class_HTTPRequest_constant_RESULT_CHUNKED_BODY_SIZE_MISMATCH:
  49. .. _class_HTTPRequest_constant_RESULT_CANT_CONNECT:
  50. .. _class_HTTPRequest_constant_RESULT_CANT_RESOLVE:
  51. .. _class_HTTPRequest_constant_RESULT_CONNECTION_ERROR:
  52. .. _class_HTTPRequest_constant_RESULT_SSL_HANDSHAKE_ERROR:
  53. .. _class_HTTPRequest_constant_RESULT_NO_RESPONSE:
  54. .. _class_HTTPRequest_constant_RESULT_BODY_SIZE_LIMIT_EXCEEDED:
  55. .. _class_HTTPRequest_constant_RESULT_REQUEST_FAILED:
  56. .. _class_HTTPRequest_constant_RESULT_DOWNLOAD_FILE_CANT_OPEN:
  57. .. _class_HTTPRequest_constant_RESULT_DOWNLOAD_FILE_WRITE_ERROR:
  58. .. _class_HTTPRequest_constant_RESULT_REDIRECT_LIMIT_REACHED:
  59. .. _class_HTTPRequest_constant_RESULT_TIMEOUT:
  60. enum **Result**:
  61. - **RESULT_SUCCESS** = **0** --- Request successful.
  62. - **RESULT_CHUNKED_BODY_SIZE_MISMATCH** = **1**
  63. - **RESULT_CANT_CONNECT** = **2** --- Request failed while connecting.
  64. - **RESULT_CANT_RESOLVE** = **3** --- Request failed while resolving.
  65. - **RESULT_CONNECTION_ERROR** = **4** --- Request failed due to connection (read/write) error.
  66. - **RESULT_SSL_HANDSHAKE_ERROR** = **5** --- Request failed on SSL handshake.
  67. - **RESULT_NO_RESPONSE** = **6** --- Request does not have a response (yet).
  68. - **RESULT_BODY_SIZE_LIMIT_EXCEEDED** = **7** --- Request exceeded its maximum size limit, see :ref:`body_size_limit<class_HTTPRequest_property_body_size_limit>`.
  69. - **RESULT_REQUEST_FAILED** = **8** --- Request failed. (Unused)
  70. - **RESULT_DOWNLOAD_FILE_CANT_OPEN** = **9** --- HTTPRequest couldn't open the download file.
  71. - **RESULT_DOWNLOAD_FILE_WRITE_ERROR** = **10** --- HTTPRequest couldn't write to the download file.
  72. - **RESULT_REDIRECT_LIMIT_REACHED** = **11** --- Request reached its maximum redirect limit, see :ref:`max_redirects<class_HTTPRequest_property_max_redirects>`.
  73. - **RESULT_TIMEOUT** = **12**
  74. Description
  75. -----------
  76. A node with the ability to send HTTP requests. Uses :ref:`HTTPClient<class_HTTPClient>` internally.
  77. Can be used to make HTTP requests, i.e. download or upload files or web content via HTTP.
  78. Tutorials
  79. ---------
  80. - :doc:`../tutorials/networking/ssl_certificates`
  81. Property Descriptions
  82. ---------------------
  83. .. _class_HTTPRequest_property_body_size_limit:
  84. - :ref:`int<class_int>` **body_size_limit**
  85. +-----------+----------------------------+
  86. | *Default* | -1 |
  87. +-----------+----------------------------+
  88. | *Setter* | set_body_size_limit(value) |
  89. +-----------+----------------------------+
  90. | *Getter* | get_body_size_limit() |
  91. +-----------+----------------------------+
  92. Maximum allowed size for response bodies.
  93. .. _class_HTTPRequest_property_download_file:
  94. - :ref:`String<class_String>` **download_file**
  95. +-----------+--------------------------+
  96. | *Default* | "" |
  97. +-----------+--------------------------+
  98. | *Setter* | set_download_file(value) |
  99. +-----------+--------------------------+
  100. | *Getter* | get_download_file() |
  101. +-----------+--------------------------+
  102. The file to download into. Will output any received file into it.
  103. .. _class_HTTPRequest_property_max_redirects:
  104. - :ref:`int<class_int>` **max_redirects**
  105. +-----------+--------------------------+
  106. | *Default* | 8 |
  107. +-----------+--------------------------+
  108. | *Setter* | set_max_redirects(value) |
  109. +-----------+--------------------------+
  110. | *Getter* | get_max_redirects() |
  111. +-----------+--------------------------+
  112. Maximum number of allowed redirects.
  113. .. _class_HTTPRequest_property_timeout:
  114. - :ref:`int<class_int>` **timeout**
  115. +-----------+--------------------+
  116. | *Default* | 0 |
  117. +-----------+--------------------+
  118. | *Setter* | set_timeout(value) |
  119. +-----------+--------------------+
  120. | *Getter* | get_timeout() |
  121. +-----------+--------------------+
  122. .. _class_HTTPRequest_property_use_threads:
  123. - :ref:`bool<class_bool>` **use_threads**
  124. +-----------+------------------------+
  125. | *Default* | false |
  126. +-----------+------------------------+
  127. | *Setter* | set_use_threads(value) |
  128. +-----------+------------------------+
  129. | *Getter* | is_using_threads() |
  130. +-----------+------------------------+
  131. If ``true``, multithreading is used to improve performance.
  132. Method Descriptions
  133. -------------------
  134. .. _class_HTTPRequest_method_cancel_request:
  135. - void **cancel_request** **(** **)**
  136. Cancels the current request.
  137. .. _class_HTTPRequest_method_get_body_size:
  138. - :ref:`int<class_int>` **get_body_size** **(** **)** const
  139. Returns the response body length.
  140. .. _class_HTTPRequest_method_get_downloaded_bytes:
  141. - :ref:`int<class_int>` **get_downloaded_bytes** **(** **)** const
  142. Returns the amount of bytes this HTTPRequest downloaded.
  143. .. _class_HTTPRequest_method_get_http_client_status:
  144. - :ref:`Status<enum_HTTPClient_Status>` **get_http_client_status** **(** **)** const
  145. Returns the current status of the underlying :ref:`HTTPClient<class_HTTPClient>`. See ``STATUS_*`` enum on :ref:`HTTPClient<class_HTTPClient>`.
  146. .. _class_HTTPRequest_method_request:
  147. - :ref:`Error<enum_@GlobalScope_Error>` **request** **(** :ref:`String<class_String>` url, :ref:`PoolStringArray<class_PoolStringArray>` custom_headers=PoolStringArray( ), :ref:`bool<class_bool>` ssl_validate_domain=true, :ref:`Method<enum_HTTPClient_Method>` method=0, :ref:`String<class_String>` request_data="" **)**
  148. Creates request on the underlying :ref:`HTTPClient<class_HTTPClient>`. If there is no configuration errors, it tries to connect using :ref:`HTTPClient.connect_to_host<class_HTTPClient_method_connect_to_host>` and passes parameters onto :ref:`HTTPClient.request<class_HTTPClient_method_request>`.
  149. Returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` if request is successfully created. (Does not imply that the server has responded), :ref:`@GlobalScope.ERR_UNCONFIGURED<class_@GlobalScope_constant_ERR_UNCONFIGURED>` if not in the tree, :ref:`@GlobalScope.ERR_BUSY<class_@GlobalScope_constant_ERR_BUSY>` if still processing previous request, :ref:`@GlobalScope.ERR_INVALID_PARAMETER<class_@GlobalScope_constant_ERR_INVALID_PARAMETER>` if given string is not a valid URL format, or :ref:`@GlobalScope.ERR_CANT_CONNECT<class_@GlobalScope_constant_ERR_CANT_CONNECT>` if not using thread and the :ref:`HTTPClient<class_HTTPClient>` cannot connect to host.