在Flex / AS3中使用HTTPService在POST上取得进展

时间:2022-01-26 05:28:43

I'm using HTTPService with a POST operation to submit a Base64 encoded file (taken from bitmap data within the app) but I could really do with getting some idea of the progress of the POST operation (e.g. like the FileReference.upload()).

我正在使用带有POST操作的HTTPService来提交Base64编码文件(取自应用程序中的位图数据)但我真的可以了解POST操作的进度(例如FileReference.upload()) 。

I don't think this is possible, but it would be awesome if it is (via any means, I'm willing to change my setup to get this).

我不认为这是可能的,但如果是这样的话会很棒(通过任何方式,我都愿意改变我的设置来获得这个)。

3 个解决方案

#1


Do not use HTTPService. Use URLRequest, URLLoader, and URLVariables.

不要使用HTTPService。使用URLRequest,URLLoader和URLVariables。

If your using an HTTPService tag, get ride of it and replace it with a Script tag filled with something like ...

如果您使用HTTPService标记,请使用它并将其替换为填充了类似...的脚本标记。


private function forYou() : void{
     var req : URLRequest = new URLRequest("PUT YOUR URL HERE")
     var loader : URLLoader = new URLLoader();
     var params : URLVariables = new URLVariables();
     params.WHATEVER = WHATEVER YOU WANT IT TO BE;
     req.data = params;
     req.method = URLRequestMethod.POST;
     loader.addEventListener(ProgressEvent.PROGRESS, YOUR LISTENER FUNCTION NAME);
     loader.load(req);
}

Assign this function name to the creationComplete attribute of the root tag.

将此函数名称分配给根标记的creationComplete属性。

If your not using an HTTPService tag, just get ride of the HTTPService object in your actionscript and use the above code.

如果您没有使用HTTPService标记,只需在您的actionscript中获取HTTPService对象并使用上面的代码。

#2


This worked well for me to consume a REST web service:

这对我来说很适合使用REST Web服务:

http://code.google.com/p/as3httpclient/wiki/Links

Example

#3


This isn't possible with HTTPService. Its only events are result, fault, and invoke (other than the non-relevant inherited events of activate and deactivate).

HTTPService无法做到这一点。它唯一的事件是结果,错误和调用(除了激活和停用的非相关继承事件)。

To get progress information on an upload process, the server would have to provide the information, which would require a means of communication between the server and the client during the operation, which isn't there for a regular HTTP POST operation.

要获得有关上载过程的进度信息,服务器必须提供信息,这将需要在操作期间服务器和客户端之间的通信方式,这不适用于常规HTTP POST操作。

One option might be to create an object on the server that would be instantiated whenever the server began receiving POST data from your client. It would then keep track of the progress and expose that data to the rest of your server-side application. Your client could then initiate a polling system that would request the value of that particular variable.

一种选择可能是在服务器上创建一个对象,只要服务器开始从客户端接收POST数据,就会实例化该对象。然后,它将跟踪进度并将该数据公开给服务器端应用程序的其余部分。然后,您的客户端可以启动一个轮询系统,该系统将请求该特定变量的值。

Seems like kind of a far-fetched option, though...

看起来像是一种牵强的选择,但......

#1


Do not use HTTPService. Use URLRequest, URLLoader, and URLVariables.

不要使用HTTPService。使用URLRequest,URLLoader和URLVariables。

If your using an HTTPService tag, get ride of it and replace it with a Script tag filled with something like ...

如果您使用HTTPService标记,请使用它并将其替换为填充了类似...的脚本标记。


private function forYou() : void{
     var req : URLRequest = new URLRequest("PUT YOUR URL HERE")
     var loader : URLLoader = new URLLoader();
     var params : URLVariables = new URLVariables();
     params.WHATEVER = WHATEVER YOU WANT IT TO BE;
     req.data = params;
     req.method = URLRequestMethod.POST;
     loader.addEventListener(ProgressEvent.PROGRESS, YOUR LISTENER FUNCTION NAME);
     loader.load(req);
}

Assign this function name to the creationComplete attribute of the root tag.

将此函数名称分配给根标记的creationComplete属性。

If your not using an HTTPService tag, just get ride of the HTTPService object in your actionscript and use the above code.

如果您没有使用HTTPService标记,只需在您的actionscript中获取HTTPService对象并使用上面的代码。

#2


This worked well for me to consume a REST web service:

这对我来说很适合使用REST Web服务:

http://code.google.com/p/as3httpclient/wiki/Links

Example

#3


This isn't possible with HTTPService. Its only events are result, fault, and invoke (other than the non-relevant inherited events of activate and deactivate).

HTTPService无法做到这一点。它唯一的事件是结果,错误和调用(除了激活和停用的非相关继承事件)。

To get progress information on an upload process, the server would have to provide the information, which would require a means of communication between the server and the client during the operation, which isn't there for a regular HTTP POST operation.

要获得有关上载过程的进度信息,服务器必须提供信息,这将需要在操作期间服务器和客户端之间的通信方式,这不适用于常规HTTP POST操作。

One option might be to create an object on the server that would be instantiated whenever the server began receiving POST data from your client. It would then keep track of the progress and expose that data to the rest of your server-side application. Your client could then initiate a polling system that would request the value of that particular variable.

一种选择可能是在服务器上创建一个对象,只要服务器开始从客户端接收POST数据,就会实例化该对象。然后,它将跟踪进度并将该数据公开给服务器端应用程序的其余部分。然后,您的客户端可以启动一个轮询系统,该系统将请求该特定变量的值。

Seems like kind of a far-fetched option, though...

看起来像是一种牵强的选择,但......