fred basset
fred basset

Reputation: 10092

How to POST JSON using Adobe Flex

I'm trying to POST some JSON data using Adobe Flex but having some problems. I'm now getting the error message "A URL must be specified with useProxy set to false", even though I do have useProxy set to false.

Update : code below is now working.

                var data:Object = new Object();
                data.ipaddr = ipaddr.text;
                data.netmask = netmask.text;
                data.gatewayip = gatewayip.text;
                var jsonData:String = JSON.stringify(data);
                var s:mx.rpc.http.HTTPService = new mx.rpc.http.HTTPService();
                // URL needs to be specified on a separate line, call is unreliable otherwise
                s.url = Utils.getBaseURL() + '/cgi-bin/setnetworksettings';
                s.contentType = "application/json";
                s.resultFormat = mx.rpc.http.HTTPService.RESULT_FORMAT_TEXT;
                s.method = "POST";
                s.useProxy = false;
                s.addEventListener("result", httpResult);
                s.addEventListener("fault", httpFault);         
                s.send(jsonData);

Upvotes: 1

Views: 4700

Answers (1)

a.s.t.r.o
a.s.t.r.o

Reputation: 3338

What do you mean by "doesn't seem to do anything"? No response from the server? Fault instead of result? Which one? Help us help you with more details, just stating it doesn't work is not enough.

First of all, be sure that your URL is correct, you should get something in the service result handler OR fault handler, anything. That should help you diagnose and fix any URL problems if any.

Then for the JSON part, you object is not a valid JSON (no escaping and : instead of =), try sending this first: {"ipaddr":"10.1.1.1"}. From here it should be easy: as F4L stated, you can use the JSON class to encode a real object directly to JSON.

Hope that helps

Upvotes: 1

Related Questions