我有一种形式在 Asp.net 中接受 json post,我需要从 Flash As3 调用它...
我正在使用下面的代码来做到这一点。我看过一些帖子,他们说它工作正常。 但是我遇到以下错误
错误:错误 #2101:传递给 URLVariables.decode() 的字符串必须是包含名称/值对的 URL 编码查询字符串。
这是我的代码。
var messages:Array = new Array ();
messages.push({"From":fromemailTxt.text,"To": ToemailTxt.text,"Body": BodyText.text,"Subject":SubjectText.text});
var JsonObj:String = JSON.encode(messages);
trace(JsonObj);
var variables:URLVariables=new URLVariables(JsonObj);
RequestURL= srvStringURL;
var JSONLoader:URLLoader = new URLLoader();
JSONLoader.dataFormat=URLLoaderDataFormat.TEXT;
JSONLoader.addEventListener(IOErrorEvent.IO_ERROR, GetBookmarkURLError, false, 0, true);
JSONLoader.addEventListener(Event.COMPLETE, parseBookmarkURLResult, false, 0, true);
var hdr:URLRequestHeader = new URLRequestHeader("Content-type", "application/json");
var request:URLRequest = new URLRequest(RequestURL);
request.requestHeaders.push(hdr);
request.data=variables;
request.method = URLRequestMethod.POST;
try
{
JSONLoader.load(request);
}
catch (error:ArgumentError)
{
trace("An ArgumentError has occurred."+error.errorID.toString());
}
catch (error:SecurityError)
{
trace("A SecurityError has occurred.");
}
catch (error:Error)
{
trace("Unable to load requested document.");
}
有人对此有任何想法吗? 谢谢
请您参考如下方法:
错误是因为您将不正确的字符串传递给 URLVariables构造函数。不要使用 URLVariables。而是将数据作为字符串传递:request.data=JsonObj;