Difference between revisions of "UrlLoader.new"

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

Revision as of 13:38, 23 August 2018

Available since: Gideros 2012.2.2

Description


Creates a new [[[UrlLoader]]] object.

[[[url]]] parameter specifies the URL to download. This parameter is optional and if specified loading starts immediately.

[[[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 or `UrlLoader.PUT]]].

After loading is finished, loaded data is stored at [[[event.data` field of `Event.COMPLETE]]] event as string.

 UrlLoader.new(url,method,headers,body)

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

Example

local url = &quot;http://www.[yourDomain].com/application.php?userid=gideros&amp;login=guest&quot;

local loader1 = UrlLoader.new(url)
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 loader4 = UrlLoader.new(url, UrlLoader.PUT, &quot;my put data&quot;)
local loader5 = UrlLoader.new(url, UrlLoader.DELETE)

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