与具有相同名称的多个参数发送HTTP请求多个、名称、参数、HTTP

2023-09-08 11:11:20 作者:黑月亮

我需要从闪存看起来类似于以下发送HTTP请求(并获得XML响应):

I need to send a HTTP request (and get XML response) from Flash that looks similar to following:

http://example.com/somepath?data=1&data=2&data=3

即。具有共享相同的名称,但有不同的值几个参数。

I.e. having several parameters that share same name, but have different values.

到现在为止我用下面的code键使HTTP请求:

Until now I used following code to make HTTP requests:

var resp:XML = new XML();
resp.onLoad = function(success:Boolean) {/*...*/};
resp.ignoreWhite = true;

var req:LoadVars = new LoadVars();
req["someParam1"] = 3;
req["someParam2"] = 12;

req.sendAndLoad("http://example.com/somepath", resp, "GET");

在这种情况下,这不会做:将有有最后一个值只有一个参数

In this case this will not do: there will be only one parameter having last value.

我有什么选择?我使用ActionScript 2的。

What are my options? I'm using actionscript 2.

添加

我想,我可以做这样的事情:

I guess, I can do something like that:

var url:String = myCustomFunctionForBuildingRequestString();
var resp:XML = new XML();
resp.onLoad = function(success:Boolean) {/*...*/};
resp.load(url);

但在这种情况下,我失去能力做POST请求。任何替代方案?

But in that case I am loosing ability to do POST requests. Any alternatives?

改变请求是不恰当的。

推荐答案

虽然POST可以为同一个键有多个值,我会谨慎使用它,因为有些服务器甚至不能正确处理,这是也许这是为什么不支持?如果您将重复的参数列表,整个事情可能会开始呛,如果一个参数来仅一次,suddendly你风有一个字符串或东西...但我想你知道自己在做什么......

Although POST may be having multiple values for the same key, I'd be cautious using it, since some servers can't even properly handle that, which is probably why this isn't supported ... if you convert "duplicate" parameters to a list, the whole thing might start to choke, if a parameter comes in only once, and suddendly you wind up having a string or something ... but i guess you know what you're doing ...

我很抱歉这样说,但你想要做的,是不可能在纯粹的AS2 ...唯一的2类适用于HTTP是 Load忱 XML ...技术上也的loadVariables ,但它只是复制传递的对象属性进请求,这没有按'T改变你的问题,因为属性是唯一...

I am sorry to say so, but what you want to do, is not possible in pure AS2 ... the only 2 classes available for HTTP are LoadVars and XML ... technically there's also loadVariables, but it will simply copy properties from the passed object into the request, which doesn't change your problem, since properties are unique ...

如果你想坚持到AS2,你需要一个中间层:

if you want to stick to AS2, you need an intermediary tier:

在一台服务器转移呼叫。如果你有机会到服务器,然后创建了AS2客户提供新的端点,这将取消$ C C的请求,$,并将其传递给正常的终点。 使用的JavaScript。与 flash.external :: ExternalInterface的,你可以调用JavaScript code。您需要定义一个回调,当操作完成的,还有,你可以调用(还有其他的方式,但是这应该足够了)JavaScript函数。建立内部闪存的请求字符串,用泵为JavaScript和让的JavaScript它在一个POST请求发送到服务器,并获得响应回Flash通过回调。 a server to forward your calls. if you have access to the server, then you create a new endpoint for AS2 clients, which will decode the requests and pass them to the normal endpoint. use javascript. with flash.external::ExternalInterface you can call JavaScript code. You need to define a callback for when the operation is done, as well as a JavaScript function that you can call (there are other ways but this should suffice). Build the request string inside flash, pump it to JavaScript and let JavaScript send it to the server in a POST request and get the response back to flash through the callback.

由你来决定哪一个是更多的工作...

up to you to decide which one is more work ...

侧面说明:的在AS3中,你会使用 flash.net::URLLoader DATAFORMAT 设置为 flash.net::URLLoaderDataFormat.TEXT ,然后重新连接code参数为一个字符串,并把他们。

side note: in AS3, you'd use flash.net::URLLoader with dataFormat set to flash.net::URLLoaderDataFormat.TEXT, and then again encode parameters to a string, and send them.

 
精彩推荐
图片推荐