http create

From Onset Developer Wiki
http create

Type: Function
Context: Server
Introduced: v1.0.3

Description

Creates a new http identifier that you can use to send requests. Call http_destroy if you no longer need an identifier.

Syntax

http_create()

Parameters

  • This function has no parameters.

Return Value

  • Returns an new http identifier.

Example

function test_post()
	local r = http_create()
	http_set_resolver_protocol(r, "ipv4")
	http_set_protocol(r, "http")
	http_set_host(r, "ptsv2.com")
	http_set_port(r, 80)
	http_set_target(r, "/t/ozoab-1577627726/post")
	http_set_verb(r, "post")
	http_set_timeout(r, 30)
	http_set_version(r, 11)
	http_set_keepalive(r, true)
	http_set_field(r, "user-agent", "Onset Server "..GetGameVersionString())
	
	local body = ""
	body = body.."foo1="..url_encode("bar?")
	body = body.."foo2="..url_encode("?d,_:%bar2?")
	
	http_set_body(r, body)
	http_set_field(r, "content-length", string.len(body))
	http_set_field(r, "content-type", "application/x-www-form-urlencoded; charset=utf-8")
	
	if http_send(r, OnPostComplete, 1, 3.14, "OK s") == false then
		print("HTTP REQ NOT SENT :(")
		http_destroy(r)
	end
end

See also