0

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

错误 #2044:未处理的 ioError:。文本=错误 #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()

有人知道答案吗?

4

1 回答 1

0

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

    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 
    }
于 2013-11-11T03:16:48.503 回答