沿URL动作脚本发送参数

时间:2013-11-10 14:04:45

标签: flex authentication mobile actionscript last.fm

作为我正在构建的移动应用程序的一部分,我必须通过Last.FM的API进行身份验证。 正如他们在网站上记录的那样,我试图正确地格式化为url,但显然我做错了,因为我收到了错误:

错误#2044:未处理的ioError: text =错误#2032:流错误。网址:https://ws.audioscrobbler.com/2.0/?method=auth.getMobileSession

Last.FM文档:http://www.last.fm/api/mobileauth

我的代码如下:

            var username:String = "xxxxxxx";
            var password:String = "xxxxxxxxxxxx";

            var api_key:String = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
            var secret:String = "xxxxxxxxxxxxxxxxxxxxxx";

            var api_sig:String = MD5.hash( "api_key" + api_key + "methodauth.getMobileSessionpassword" + password + "username" + secret);

            var request:URLRequest = new URLRequest("https://ws.audioscrobbler.com/2.0/?method=auth.getMobileSession");
            var variables:URLVariables = new URLVariables();//create a variable container
            variables.username =username;
            variables.password = password;
            variables.api_key = api_key;
            variables.api_sig = api_sig;
            request.data = variables;
            request.method = URLRequestMethod.POST;//select the method as post/
            var loader:URLLoader = new URLLoader();
            loader.addEventListener(Event.COMPLETE, handleComplete);
            loader.load(request);//send the request with URLLoader()

有人知道答案吗?

1 个答案:

答案 0 :(得分:0)

尝试使用HTTPService而不是URLLoader。像这样的Smth:

    var http:HTTPService = new HTTPService();
    http.useProxy = false;
    http.resultFormat = "e4x";
    http.method = "POST";
    http.url = "https://ws.audioscrobbler.com/2.0/?method=auth.getMobileSession";
    var variables:Object = {};
    variables.username = username;
    variables.password = password;
    variables.api_key = api_key;
    variables.api_sig = api_sig;

    var token:AsyncToken = http.send(variables);
    var responder:Responder = new Responder(handleRequestComplete, handleError);
    token.addResponder(responder);

其中handleRequestComplete和handleError是请求结果的处理程序:

    private function handleRequestComplete(event:ResultEvent):void
    { 
        // your code here 
    }

    private function handleError(event:FaultEvent):void
    { 
        // your code here 
    }
相关问题