Getting JSON object from php authentication objective c

Posted by iError on Stack Overflow See other posts from Stack Overflow or by iError
Published on 2012-06-27T18:55:45Z Indexed on 2012/06/27 21:16 UTC
Read the original article Hit count: 194

Filed under:
|
|
|
|

I am trying to authenticate using the below code

NSString *urlAsString =[NSString stringWithFormat:@"http://www.myurl.com/abc/authenticate.php"];

    NSURL *url = [NSURL URLWithString:urlAsString];

    NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url]; 

    [urlRequest setTimeoutInterval:30.0f];

    [urlRequest setHTTPMethod:@"POST"];

    [urlRequest addValue:@"test" forHTTPHeaderField:@"m_username" ];

    [urlRequest addValue:@"123" forHTTPHeaderField:@"m_password" ];

    [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];

    NSOperationQueue *queue = [[NSOperationQueue alloc] init];

    [NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response,NSData *data, NSError *error) {

        if ([data length] >0 && error == nil){

            html = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

            NSLog(@"HTML = %@", html);

            receivedData = [NSMutableData data];

        }
        else if ([data length] == 0 && error == nil){

            NSLog(@"Nothing was downloaded."); 

        }

        else if (error != nil){

            NSLog(@"Error happened = %@", error);
        } 
    }];

    // Start loading data
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
    if (theConnection) 
    {
        // Create the NSMutableData to hold the received data
        receivedData = [NSMutableData data];

    } 
    else {
        // Inform the user the connection failed.

    }

My username password is correct, I think I am not making the proper call thats why I dont get the desired results and the web service is receiving the null parameters.

What can be the issue?

Any help appreciated.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about ios