3

How to send array in Httpservice in Adobe Flex3

4 Answers 4

7

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

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

0

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.

Comments

0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.