Difference between revisions of "http send"

From Onset Developer Wiki
(Created page with "{{Info|Function|Server|1.0.3}} {{FuncDescription|Sends an http request.}} {{FuncSyntax|http_send(http)}} {{FuncParameters}} {{FuncParam|http|The http identifier.}} {{FuncR...")
 
 
Line 3: Line 3:
 
{{FuncDescription|Sends an http request.}}
 
{{FuncDescription|Sends an http request.}}
  
{{FuncSyntax|http_send(http)}}
+
{{FuncSyntax|http_send(http [, LuaFunction, UserArgs...])}}
  
 
{{FuncParameters}}
 
{{FuncParameters}}
 
{{FuncParam|http|The http identifier.}}
 
{{FuncParam|http|The http identifier.}}
 +
{{FuncParamOptional|LuaFunction|The function to call on completion.}}
 +
{{FuncParamOptional|UserArgs|Arguments to pass to the function.}}
  
 
{{FuncReturnValue|Returns '''true''' if the request was successfully sent. '''false''' otherwise.}}
 
{{FuncReturnValue|Returns '''true''' if the request was successfully sent. '''false''' otherwise.}}
Line 26: Line 28:
 
http_set_field(r, "user-agent", "Onset Server "..GetGameVersionString())
 
http_set_field(r, "user-agent", "Onset Server "..GetGameVersionString())
 
 
if http_send(r, OnGetComplete, "Str L", 88.88, 1337) == false then
+
if http_send(r, OnGetComplete, "Str L", 3.1415, 1337) == false then
 
print("HTTP REQ NOT SENT :(")
 
print("HTTP REQ NOT SENT :(")
 
http_destroy(r)
 
http_destroy(r)

Latest revision as of 12:43, 28 June 2020

http send

Type: Function
Context: Server
Introduced: v1.0.3

Description

Sends an http request.

Syntax

http_send(http [, LuaFunction, UserArgs...])

Parameters

  • http
    The http identifier.
  • LuaFunction (optional)
    The function to call on completion.
  • UserArgs (optional)
    Arguments to pass to the function.

Return Value

  • Returns true if the request was successfully sent. false otherwise.

Example

function test_get()
	local r = http_create()
	http_set_resolver_protocol(r, "any")
	http_set_protocol(r, "https")
	http_set_host(r, "postman-echo.com")
	http_set_port(r, 443)
	http_set_verifymode(r, "verify_peer")
	http_set_target(r, "/get?foo=bar&onset=nice")
	http_set_verb(r, "get")
	http_set_timeout(r, 30)
	http_set_version(r, 11)
	http_set_keepalive(r, false)
	http_set_field(r, "user-agent", "Onset Server "..GetGameVersionString())
	
	if http_send(r, OnGetComplete, "Str L", 3.1415, 1337) == false then
		print("HTTP REQ NOT SENT :(")
		http_destroy(r)
	end
end

function OnGetComplete(a, b, c)
	print("OnGetComplete", a, b, c)
end

See also