httpGet: Difference between revisions

265 bytes removed ,  19 November 2022
no edit summary
No edit summary
No edit summary
 
Line 1: Line 1:
{{ScriptItem
{{ScriptItem2
|endpoint = server
|name = httpGet
|side = server
|type = function
|type = function
|name = httpGet
|games = iii vc sa iv
|parameters = string url, string postData, function dataReceivedCallback, function completedCallback
|desc = perform a HTTP transfer asynchronously.<br><br>
|parameter1 = string url The URL to send the HTTP request to.
|parameter2 = string postData The data to send as the body of the HTTP request.
|parameter3 = function dataReceivedCallback The scripting function to call when data is read from the connection. This can be called multiple times.
|parameter4 = function completedCallback The scripting function to call when data has been entirely read on the connection.
|return1 = void
|returnFail1 = void
|usage = perform a HTTP transfer asynchronously.<br><br>


If parameter <code>postData</code> is a blank string, then the GET request method is used, otherwise the POST request method is used.
If parameter <code>postData</code> is a blank string, then the GET request method is used, otherwise the POST request method is used.
|callback3Syntax = ArrayBuffer/String receivedData
|arg1 = string url The URL to send the HTTP request to.
|callback3Text = This callback function can potentially be called multiple times for the same request.
|arg2 = string postData The data to send as the body of the HTTP request.
|callback3Parameter1 = ArrayBuffer/String receivedData The data received, which could be all of the data or just 1 byte.<br>ArrayBuffer is used in JavaScript, String is used in other scripting languages.
|arg3 = function dataReceivedCallback The scripting function to call when data is read from the connection. This can be called multiple times.
|callback4Syntax = int curlErrorCode, int httpResponseCode
|arg4 = function completedCallback The scripting function to call when data has been entirely read on the connection.
|callback4Parameter1 = int curlErrorCode The CURL error code. 0 means success. [https://curl.haxx.se/libcurl/c/libcurl-errors.html CURL Error Codes]
|return = void
|callback4Parameter2 = int httpResponseCode The HTTP response code. [https://en.wikipedia.org/wiki/List_of_HTTP_status_codes HTTP Response Codes]
|freturn = void
|note = You can use this function to convert a JavaScript ArrayBuffer to a JavaScript String:
{{CodeSyntax|function ab2str(buf) {
  return String.fromCharCode.apply(null, new Uint8Array(buf));
} }}
|cb3text = This callback function can potentially be called multiple times for the same request.
|cb3arg1 = ArrayBuffer/String receivedData The data received, which could be all of the data or just 1 byte.<br>ArrayBuffer is used in JavaScript, String is used in other scripting languages.
|cb4arg1 = int curlErrorCode The CURL error code. 0 means success. [https://curl.haxx.se/libcurl/c/libcurl-errors.html CURL Error Codes]
|cb4arg2 = int httpResponseCode The HTTP response code. [https://en.wikipedia.org/wiki/List_of_HTTP_status_codes HTTP Response Codes]
|compat1 = In server version 1.1.22 and before, there was an issue where the connection would close after the '''dataReceivedCallback''' callback was called first time and did not return the received data length.
|compat1 = In server version 1.1.22 and before, there was an issue where the connection would close after the '''dataReceivedCallback''' callback was called first time and did not return the received data length.
|compat2 = In server version 1.1.22 and before, there was also an issue where the POST request method was used if the '''postData''' parameter was a blank string.
|compat2 = In server version 1.1.22 and before, there was also an issue where the POST request method was used if the '''postData''' parameter was a blank string.
|compat3 = In previous server versions, for the JavaScript scripting language, the '''dataReceivedCallback''' callback was invoked with a string parameter instead of an ArrayBuffer parameter.
|compat3 = In previous server versions, for the JavaScript scripting language, the '''dataReceivedCallback''' callback was invoked with a string parameter instead of an ArrayBuffer parameter.
|notes = You can use this function to convert a JavaScript ArrayBuffer to a JavaScript String:
{{CodeSyntax|function ab2str(buf) {
  return String.fromCharCode.apply(null, new Uint8Array(buf));
} }}
}}
}}
6,833

edits