Flash / App Engine request data encoding problem (GET works, POST fails)
I'm new to Flash and trying to communicate with an app engine server but I'm having some encoding problems.
var playerLoader:URLLoader = new URLLoader();
playerLoader.addEventListener( Event.COMPLETE, function(e:Event) { doStuff(); } );
var requestVars:URLVariables = new URLVariables();
requestVars.q = "åäö";
var urlRequest:URLRequest = new URLRequest( serverUrl );
urlReq开发者_运维百科uest.method = URLRequestMethod.POST;
urlRequest.data = requestVars;
playerLoader.load( urlRequest );
This does not work, gives me some encoding errors on the server side. But if I switch POST to GET it automagically works.
Any clues what's going on and how I could use POST?
Thanks!
As far as I know, Actionscript's HTTP requests will natively be encoded in UTF-8.
I have it working this way for spanish chars:
var url:String = "historia.php";
var request:URLRequest = new URLRequest(url);
var requestVars:URLVariables = new URLVariables();
var now:Date = new Date();
requestVars.historia = "áóíúéñÁÓÍÚÉÑ";
request.data = requestVars;
request.method = URLRequestMethod.POST;
var urlLoader:URLLoader = new URLLoader();
urlLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
urlLoader.load(request);
And on the PHP side (resumed for clarity):
header ('Content-type: text/html; charset=utf-8');
if(isset($_POST['historia']) {
$historia = mysql_real_escape_string(utf8_decode($_POST['historia']));
$historia = filter_var($historia, FILTER_SANITIZE_STRING);
// insert into DB...
}
I use utf8_decode()
because the database is not configured with encoding UTF-8
.
How are you handling the request on the server side? Maybe the problem lies on the server side.
精彩评论