在 Flex/AS3 中使用 HTTPService 获取 POST 进度

发布于 2024-07-11 07:41:08 字数 169 浏览 7 评论 0原文

我使用 HTTPService 和 POST 操作来提交 Base64 编码文件(取自应用程序内的位图数据),但我确实可以了解 POST 操作的进度(例如,像 FileReference.upload()) 。

我认为这是不可能的,但如果是的话那就太棒了(通过任何方式,我愿意改变我的设置来实现这一点)。

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()).

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

内心激荡 2024-07-18 07:41:08

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

如果您使用 HTTPService 标记,请摆脱它并将其替换为填充类似以下内容的 Script 标记:


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);
}

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

如果您不使用 HTTPService 标记,只需在操作脚本中使用 HTTPService 对象并使用上面的代码即可。

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

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


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.

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

栖竹 2024-07-18 07:41:08

这对我使用 REST Web 服务效果很好:

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

示例

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

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

Example

泪眸﹌ 2024-07-18 07:41:08

这对于 HTTPService 来说是不可能的。 它唯一的事件是 resultfaultinvoke(除了不相关的继承事件 activate停用)。

要获取上传过程的进度信息,服务器必须提供该信息,这需要在操作期间服务器和客户端之间有一种通信方式,而常规 HTTP POST 操作则不具备这种通信方式。

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

不过,这似乎是一个牵强的选择......

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).

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.

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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文