[SOLVED]Problem with mobileAuth: Must use POST

  • [SOLVED]Problem with mobileAuth: Must use POST


    I got some problems with my mobile app. I have developed a last.fm ObjC wrapper for mobile auth. Everything worked fine until 2 days, the mobileAuth doesn't work anymore.
    I got an error code 4 with text "You must use POST in order to use this method".
    The problem is: I do use post...

    NSMutableDictionary* args = [NSMutableDictionary dictionary];
    [args setObject:_kECLastfmEngineAPIKey forKey:@"api_key"];
    [args setObject:@"auth.getMobileSession" forKey:@"method"];
    [args setObject:password forKey:@"password"];
    [args setObject:username forKey:@"username"];

    [args setObject:[ECLastfmEngine APISignatureWithArgs:args] forKey:@"api_sig"];

    [self startRequestWithArguments:args
    completion:^(NSDictionary *resultDict, NSError *error) {
    // Do something.
    NSLog(@"%@", resultDict); // I got the error in the dictionary

    And here's the -start method of my "ECLastfmRequest" object:

    - (void)start
    if(_connection != nil) return;

    _data = [[NSMutableData alloc] init];

    NSMutableString* urlAsString = [NSMutableString stringWithString:_kECLastfmEngineScrobblerAPIURL];
    NSMutableString* content = [NSMutableString string];
    for(NSString* aKey in [[self arguments] allKeys])
    [content appendString:aKey];
    [content appendString:@"="];
    [content appendString:[(NSString*)[[self arguments] objectForKey:aKey] encodedURLString]];

    if([[[self arguments] allKeys] lastObject]!=aKey)
    [content appendString:@"&"];

    if([self post] == NO)
    [urlAsString appendString:content];

    NSMutableURLRequest *mutableRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlAsString]];

    if([self post])
    [mutableRequest setHTTPMethod:@"POST"];
    [mutableRequest setValue:[NSString stringWithFormat:@"%d", [[content dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES] length]] forHTTPHeaderField:@"Content-Length"];
    [mutableRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [mutableRequest setHTTPBody:[content dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]];

    _connection = [[NSURLConnection alloc] initWithRequest:mutableRequest delegate:self];
    [_connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
    [_connection start];

    [mutableRequest release];

    I have not modified my code since the app has been released on the App Store, but it just started to fail for no reason. I suppose there's something wrong with the last.fm API?

    I don't even know if I should contact last.fm.. I'm pretty sure that there's nothing wrong with my code.


    Edited by tburny on 29 Aug 2012, 15:57
    • tburny said...
    • Forum Moderator
    • 29 Aug 2012, 13:35
    I'll take a look at it :)

    Combo.fm: Combine your favourite radio stations! | My Blog | scala-lastfmapi | Cache2k - A high performance Java in-memory cache
    P.S.: Do not click here
    throw new PokemonException(); //Gotta catch 'em all
    My forum post reflects my personal opinion :)
  • Can you verify that you are using post, e.g. by putting a debug proxy or something else in the middle? Or even better: can you give us a curl request that fails (with a bogus password, of course) so we can debug against it?

  • Sorry, I found the problem. We're going to deploy a fix today.

  • Thanks for your both answers.
    Edit: just saw your post, this is awesome! Thank you!!!

  • Fix is deployed and live. Thanks for letting us know :)

Anonymous users may not post messages. Please log in or create an account to post in the forums.