Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

actionscript - Sending HTTP request with multiple parameters having same name

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.

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.

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

Added

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

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

Changing request is not appropriate.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The standard http way of sending array data is

http://example.com/?data[0]=1&data[1]=2

But this isn't wrong either (added from comment):

http://example.com/?data[]=1&data[]=2

Sending more parameters with the same name like you're doing, in practice means that all but the last item should be ignored. This is because when reading variables, the server overwrites (in memory) any item that has the same name as that one, because renaming a variable isn't good practice and never was.

I don't know much AS (none :p) but you'd access it as a list or array or whatever data structures it has.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...