HttpService

Supports a function to send an HTTP request.

# Properties

[{"index":"boolean httpEnabled","0":"Allows the http:\/\/ protocol. The default value is false, and the https:\/\/ protocol is recommended for the World that will be released."}]

# Methods

[{"index":"string GetAndWait(string url, Dictionary headers = nil) (ServerOnly) (Yield)","0":"Receives the application\/json response with Http Get request. Data to be included in the header of the tables is sent to headers with the format of key - value tables."}]

[{"index":"table JSONDecode(string input)","0":"Converts the json string to the lua table variable."}]

[{"index":"string JSONEncode(table input)","0":"Converts the Lua table to the Json string."}]

[{"index":"string PostAndWait(string url, string content, HttpContentType contentType = HttpContentType.ApplicationJson, Dictionary headers = nil) (ServerOnly) (Yield)","0":"Can send HTTP Post requests. Supported formats: content, application\/json, application\/x-www-form-urlencoded, and plain\/text. Declare it in the header of tables with the format of key - value tables."}]

[{"index":"string RequestAndWait(string url, string httpMethod = nil, string content = nil, Dictionary headers = nil) (ServerOnly) (Yield)","0":"Sends Http request and gets a response. httpMethod supports get, post, put, delete, head. Content format must be specified in headers."}]

[{"index":"string UrlEncode(string input)","0":"Replaces Korean letters, spaces, and special characters in Url with escape letters."}]

##### inherited from Service:

[{"index":"EventHandlerBase ConnectEvent(string key, IScriptFunction eventHandler)","0":"Links events. When a key-type event occurs in this service, a handler is notified. The handler receives event parameters."}]

[{"index":"EventHandlerBase ConnectEvent(Type eventType, IScriptFunction eventHandler)","0":"Links events. This service notifies a handler when an eventType event occurs. The handler receives event parameters."}]

[{"index":"boolean DisconnectEvent(string key, EventHandlerBase eventHandler)","0":"Disconnects the event with the key-type event and the handler."}]

[{"index":"boolean DisconnectEvent(Type eventType, EventHandlerBase eventHandler)","0":"Disconnects the eventType event from its handler."}]

[{"index":"void SendEvent(EventType sendEvent)","0":"Generates an event."}]

# Notice

  1. Supports only HttpMethod Get/Post.
  2. 3 types of PostAsync transmission type (HttpContentType).


  * application/json
  * application/x-www-urlencoded
  * text/plain


  3. Limit to a maximum of 120 Http requests per minute. If exceeded, HttpService requests are not possible for 30 seconds.
  4. Timeout for each request is 30 seconds.
  5. Supports only Tls1.2 and above. For Tls1.0 and Tls1.1, an error occurs when attempting to communicate.
  6. Use is restricted to ports less than 1024 except 80 and 443. (＜1024) The MOD embedded server designation band is 30011 - 30019.
  7. The response buffer is limited to 10 MB.



# Examples

This is an example to send Http request and receive a response.
    
    
    @Component
    script ServerWebRequester extends Component
        @ExecSpace("ServerOnly")
        method void GetAndWait()
        local headers = {["header1"] = "value1", ["header2"] = "value2"}
        local response = _HttpService:GetAndWait("Http://WebUrl", headers)
    
        log (response)
        end
    
        @ExecSpace("ServerOnly")
        method void PostAndWait()
        local headers = {["header1"] = "value1", ["header2"] = "value2"}
        local content = {["id"] = "msw123", ["password"] = "abcd1234"}
        local contentJson = _HttpService:JSONEncode(content)
        local response = _HttpService:PostAndWait("Http://WebUrl", contentJson, HttpContentType.ApplicationJson, headers)
    
        log (response)
        end
    
        @ExecSpace("ServerOnly")
        method void RequestAndWait()
        -- Content type must be included in the header.
        local headers = {["content-type"] = "application/json", ["header1"] = "value1", ["header2"] = "value2"}
        local content = {["id"] = "msw123", ["password"] = "abcd1234"}
        local contentJson = _HttpService:JSONEncode(content)
        local response = _HttpService:RequestAndWait("Http://WebUrl", "POST", contentJson, headers)
    
        log (response)
        end
    end