LANE
LANE

Reputation: 139

How to send array through HTTPservice in Adobe Flex 3

How to send array in Httpservice in Adobe Flex3

Upvotes: 3

Views: 9824

Answers (4)

bartv
bartv

Reputation: 197

I am not quite sure what you mean by sending an array to a httpservice. If you mean to send an array to a httpservice with the same field name, you can pass an array as field value.

var service:HTTPService = new HTTPService();
service.useProxy = true;
service.destination = "myservicet";
service.resultFormat = HTTPService.RESULT_FORMAT_XML;

var fields:Array = ["categories", "organisation"];
var params:Object = new Object();
params.q = "stackoverflow";
params.rows = 0;
params.facet = "true";
params["facet.field"] = fields;
service.send(params);

The HTTPService will convert this to the url parameters:

facet=true&q=stackoverflow&facet%2Efield=categories&facet%2Efield=organisation&rows=0

Hope this helps!

Added for more clarity. When there is only 1 argument in the array, do not pass the fields as an array. For some reason, flex will not send this to the http service

Upvotes: 7

Sri
Sri

Reputation: 5845

If it is a simple array, you could send it as a comma separated string.

httpService.request = new Object;
httpService.request.csv = array.toString();

Upvotes: 0

user56250
user56250

Reputation:

It really depends what is the back end technology you're using. If you're sending it to PHP you could try:

var fields:Array = ["categories", "organisation"];
var params:Object = {};
params.q = "stackoverflow";
params.rows = 0;
params.facet = "true";
params["facet.field[]"] = fields;
service.send(params);

PHP will generate an array for you. AFAIR this works fine in Rails as well.

Upvotes: 2

Carlo
Carlo

Reputation: 2112

if it is a simple string array, you can join it with a well know separator char, and on the other site, split the string with the same separator back to an array.

Upvotes: 0

Related Questions