You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ha...@apache.org on 2023/08/13 08:00:21 UTC

[royale-asjs] branch develop updated: Added execute method for HttpRequestTask

This is an automated email from the ASF dual-hosted git repository.

harbs pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new 527ab9a1ce Added execute method for HttpRequestTask
527ab9a1ce is described below

commit 527ab9a1cea74ecdb7f06d4aa82b37e55dcd9526
Author: Harbs <ha...@in-tools.com>
AuthorDate: Sun Aug 13 10:59:56 2023 +0300

    Added execute method for HttpRequestTask
---
 .../royale/org/apache/royale/utils/async/HttpRequestTask.as  | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/frameworks/projects/Network/src/main/royale/org/apache/royale/utils/async/HttpRequestTask.as b/frameworks/projects/Network/src/main/royale/org/apache/royale/utils/async/HttpRequestTask.as
index 98b7b7abb2..6aca4c6478 100644
--- a/frameworks/projects/Network/src/main/royale/org/apache/royale/utils/async/HttpRequestTask.as
+++ b/frameworks/projects/Network/src/main/royale/org/apache/royale/utils/async/HttpRequestTask.as
@@ -136,6 +136,16 @@ package org.apache.royale.utils.async
 		{
 			fail();
 		}
-
+		public static function execute(url:String, callback:Function, method:String = HTTPConstants.GET, parameters:Object = null, contentType:String = HTTPConstants.FORM_URL_ENCODED, requestHeaders:Array = null):void
+		{
+			var task:HttpRequestTask = new HttpRequestTask();
+			task.url = url;
+			task.contentType = contentType;
+			task.method = method;
+			task.requestHeaders = requestHeaders;
+			task.parameters = parameters;
+			task.done(callback);
+			task.run();
+		}
 	}
 }
\ No newline at end of file


Re: [royale-asjs] branch develop updated: Added execute method for HttpRequestTask

Posted by Harbs <ha...@gmail.com>.
FYI, this commit makes network requests as easy as:

HttpRequestTask.execute(url,function(task:HttpRequestTask):void{
  if(task.completed){
    // do completed stuff with task.httpResult
  } else {
    //handle error
  }
});

Or if you need a POST request with parameters:

HttpRequestTask.execute(url,function(task:HttpRequestTask):void{
  if(task.completed){
    // do completed stuff with task.httpResult
  } else {
    //handle error
  }
},HTTPConstants.POST,params);

for a JSON POST request:

HttpRequestTask.execute(url,function(task:HttpRequestTask):void{
  if(task.completed){
    // do completed stuff with task.httpResult
  } else {
    //handle error
  }
},HTTPConstants.POST,json,HTTPHeader.APPLICATION_JSON);

HTH,
Harbs

> On Aug 13, 2023, at 11:00 AM, harbs@apache.org wrote:
> 
> This is an automated email from the ASF dual-hosted git repository.
> 
> harbs pushed a commit to branch develop
> in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
> 
> 
> The following commit(s) were added to refs/heads/develop by this push:
>     new 527ab9a1ce Added execute method for HttpRequestTask
> 527ab9a1ce is described below
> 
> commit 527ab9a1cea74ecdb7f06d4aa82b37e55dcd9526
> Author: Harbs <ha...@in-tools.com>
> AuthorDate: Sun Aug 13 10:59:56 2023 +0300
> 
>    Added execute method for HttpRequestTask
> ---
> .../royale/org/apache/royale/utils/async/HttpRequestTask.as  | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/frameworks/projects/Network/src/main/royale/org/apache/royale/utils/async/HttpRequestTask.as b/frameworks/projects/Network/src/main/royale/org/apache/royale/utils/async/HttpRequestTask.as
> index 98b7b7abb2..6aca4c6478 100644
> --- a/frameworks/projects/Network/src/main/royale/org/apache/royale/utils/async/HttpRequestTask.as
> +++ b/frameworks/projects/Network/src/main/royale/org/apache/royale/utils/async/HttpRequestTask.as
> @@ -136,6 +136,16 @@ package org.apache.royale.utils.async
> 		{
> 			fail();
> 		}
> -
> +		public static function execute(url:String, callback:Function, method:String = HTTPConstants.GET, parameters:Object = null, contentType:String = HTTPConstants.FORM_URL_ENCODED, requestHeaders:Array = null):void
> +		{
> +			var task:HttpRequestTask = new HttpRequestTask();
> +			task.url = url;
> +			task.contentType = contentType;
> +			task.method = method;
> +			task.requestHeaders = requestHeaders;
> +			task.parameters = parameters;
> +			task.done(callback);
> +			task.run();
> +		}
> 	}
> }
> \ No newline at end of file
>