HTTPService:它的send方法在做什么?

时间:2011-08-12 14:08:27

标签: actionscript-3

我有一个JSON字符串:

query = {"action":"do","password":"c","name":"s"}

使用HTTPService的send方法时:

_service = new HTTPService();
_service.url = "http://localhost:8080";
_service.method = "POST";
_service.contentType = "application/json";
_service.resultFormat = "text";
_service.useProxy = false;
_service.makeObjectsBindable = true;
_service.addEventListener(FaultEvent.FAULT,faultRX);
_service.addEventListener(ResultEvent.RESULT,resultRX);
_service.showBusyCursor = true;
var _request:Object = new Object();
_request.query = query;
_service.request = _request;
_service.send();

我不知道我做错了什么,但在我的HTTP服务器上我得到了:

{["object","Object"]}

有任何线索吗? 感谢

2 个答案:

答案 0 :(得分:0)

您正在声明对象的对象。

尝试:

_service.request = query;
_service.send();

答案 1 :(得分:0)

你得到了

{["object","Object"]}

因为这个

var _request:Object = new Object();
_request.query = query;
_service.request = _request;


这样做

 var jsonOBJ:Object = {};
     jsonOBJ.action = "do";
     jsonOBJ.password = "c";
     jsonOBJ.name = "s";

var _service:HTTPService = new HTTPService();
    _service.url = "http://localhost:8080";
    _service.method = "POST";
    _service.contentType = "application/json";
    _service.resultFormat = "text";
    _service.useProxy = false;
    _service.makeObjectsBindable = true;
    _service.addEventListener(FaultEvent.FAULT,faultRX);
    _service.addEventListener(ResultEvent.RESULT,resultRX);
    _service.showBusyCursor = true;
    _service.send( JSON.encode( jsonOBJ ) );// encode the json object with AS3Corelib

不要忘记顶级JSON解码服务器端的字符串。