Difference between revisions of "UrlLoader.new"

From GiderosMobile
m (Text replacement - "<source" to "<syntaxhighlight")
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
'''<translate>Available since</translate>:''' Gideros 2012.2.2<br/>
+
'''Available since:''' Gideros 2012.2.2<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/UrlLoader|UrlLoader]]<br/>
+
'''Class:''' [[UrlLoader]]<br/>
=== <translate>Description</translate> ===
+
 
<translate><br />
+
=== Description ===
Creates a new [[Special:MyLanguage/UrlLoader|UrlLoader]] object.<br />
+
Creates a new '''UrlLoader''' object.
<br />
+
<syntaxhighlight lang="lua">
''url'' parameter specifies the URL to download. This parameter is optional and if specified loading starts immediately.<br />
+
UrlLoader.new(url,method,headers,body)
<br />
 
''method'' parameter specifies the HTTP request method. It can be one of the values of [[Special:MyLanguage/UrlLoader.GET|UrlLoader.GET]], [[Special:MyLanguage/UrlLoader.POST|UrlLoader.POST]], [[Special:MyLanguage/UrlLoader.PUT|UrlLoader.PUT]] or [[Special:MyLanguage/UrlLoader.DELETE|UrlLoader.DELETE]].<br />
 
The default HTTP method is [[Special:MyLanguage/UrlLoader.GET|UrlLoader.GET]].<br />
 
<br />
 
''body'' parameter specifies the HTTP body data. This parameter is used only when the HTTP method is [[Special:MyLanguage/UrlLoader.POST|UrlLoader.POST]] or or [[Special:MyLanguage/UrlLoader.PUT|UrlLoader.PUT]].<br />
 
<br />
 
After loading is finished, loaded data is stored at ''event.data'' field of [[Special:MyLanguage/Event.COMPLETE|Event.COMPLETE]] event as string.<br />
 
<br /></translate>
 
<source lang="lua">
 
UrlLoader.new(url,method,headers,body)
 
 
</source>
 
</source>
=== <translate>Parameters</translate> ===
+
 
'''url''': (string, optional) <translate>URL to download. This parameter is optional and if specified loading starts immediately.</translate> <br/>
+
 
'''method''': (string, default = &quot;get&quot;) <translate>HTTP request method.</translate> <br/>
+
''method'' parameter specifies the HTTP request method. It can be one of the values of '''[[UrlLoader.GET]]''', '''[[UrlLoader.POST]]''', '''[[UrlLoader.PUT]]''' or '''[[UrlLoader.DELETE]]'''. The default HTTP method is '''UrlLoader.GET'''
'''headers''': (table, optional) <translate>HTTP headers.</translate> <br/>
+
 
'''body''': (string, optional) <translate>HTTP body data. This data is sent as the message body of a request.</translate> <br/>
+
''body'' parameter specifies the HTTP body data. This parameter is used only when the HTTP method is '''UrlLoader.POST''' or '''UrlLoader.PUT'''
=== <translate>Examples</translate> ===
+
 
'''Example'''<br/>
+
 
<source lang="lua">local url = &quot;http://www.[yourDomain].com/application.php?userid=gideros&amp;login=guest&quot;
+
After loading is finished, loaded data is stored as a string in the ''event.data'' field of [[Event.COMPLETE]] event.
 +
 
 +
=== Parameters ===
 +
'''url''': (string, optional) URL to download. This parameter is optional and if specified loading starts immediately<br/>
 +
'''method''': (string, default = "get") HTTP request method<br/>
 +
'''headers''': (table, optional) HTTP headers<br/>
 +
'''body''': (string, optional) HTTP body data. This data is sent as the message body of a request<br/>
 +
 
 +
=== Examples ===
 +
<syntaxhighlight lang="lua">
 +
local url = "http://www.[yourDomain].com/application.php?userid=gideros&login=guest"
  
 
local loader1 = UrlLoader.new(url)
 
local loader1 = UrlLoader.new(url)
 
local loader2 = UrlLoader.new(url, UrlLoader.GET) -- same as the previous line
 
local loader2 = UrlLoader.new(url, UrlLoader.GET) -- same as the previous line
local loader3 = UrlLoader.new(url, UrlLoader.POST, &quot;my post data&quot;)
+
local loader3 = UrlLoader.new(url, UrlLoader.POST, "my post data")
local loader4 = UrlLoader.new(url, UrlLoader.PUT, &quot;my put data&quot;)
+
local loader4 = UrlLoader.new(url, UrlLoader.PUT, "my put data")
 
local loader5 = UrlLoader.new(url, UrlLoader.DELETE)
 
local loader5 = UrlLoader.new(url, UrlLoader.DELETE)
  
 
local headers = {
 
local headers = {
[&quot;Content-Type&quot;] = &quot;application/x-www-form-urlencoded&quot;,
+
["Content-Type"] = "application/x-www-form-urlencoded",
[&quot;User-Agent&quot;] = &quot;Gideros Browser&quot;,
+
["User-Agent"] = "Gideros Browser",
 
}
 
}
local loader6 = UrlLoader.new(url, UrlLoader.PUT, headers, &quot;key=value&quot;)</source>
+
local loader6 = UrlLoader.new(url, UrlLoader.PUT, headers, "key=value")
 +
</source>
 +
 
 +
{{UrlLoader}}

Latest revision as of 14:32, 13 July 2023

Available since: Gideros 2012.2.2
Class: UrlLoader

Description

Creates a new UrlLoader object. <syntaxhighlight lang="lua"> UrlLoader.new(url,method,headers,body) </source>


method parameter specifies the HTTP request method. It can be one of the values of UrlLoader.GET, UrlLoader.POST, UrlLoader.PUT or UrlLoader.DELETE. The default HTTP method is UrlLoader.GET
body parameter specifies the HTTP body data. This parameter is used only when the HTTP method is UrlLoader.POST or UrlLoader.PUT


After loading is finished, loaded data is stored as a string in the event.data field of Event.COMPLETE event.

Parameters

url: (string, optional) URL to download. This parameter is optional and if specified loading starts immediately
method: (string, default = "get") HTTP request method
headers: (table, optional) HTTP headers
body: (string, optional) HTTP body data. This data is sent as the message body of a request

Examples

<syntaxhighlight lang="lua"> local url = "http://www.[yourDomain].com/application.php?userid=gideros&login=guest"

local loader1 = UrlLoader.new(url) local loader2 = UrlLoader.new(url, UrlLoader.GET) -- same as the previous line local loader3 = UrlLoader.new(url, UrlLoader.POST, "my post data") local loader4 = UrlLoader.new(url, UrlLoader.PUT, "my put data") local loader5 = UrlLoader.new(url, UrlLoader.DELETE)

local headers = { ["Content-Type"] = "application/x-www-form-urlencoded", ["User-Agent"] = "Gideros Browser", } local loader6 = UrlLoader.new(url, UrlLoader.PUT, headers, "key=value") </source>