How to use Asihttprequest asynchronous requests server?

82 views Asked by At

My server login parameters:

username
password (md5 encrypted)
logintype

Return parameter:

userId
username
levelid
mobilenum
email
  • 0 Success
  • 10001 account name can not be empty
  • 10002 account does not exist
  • 10003 password is incorrect
  • 10004 Invalid account
1

There are 1 answers

1
Neenu On

Try this,

#import <CommonCrypto/CommonDigest.h>

NSString *md5(NSString *str) {
    const char *cStr = [str UTF8String];
    unsigned char result[CC_MD5_DIGEST_LENGTH];
    CC_MD5( cStr, strlen(cStr), result );
    return [NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
            result[0], result[1],
            result[2], result[3],
            result[4], result[5],
            result[6], result[7],
            result[8], result[9],
            result[10], result[11],
            result[12], result[13],
            result[14], result[15]
            ];
}

- (IBAction)grabURLInBackground:(id)sender
{
    NSURL *url = [NSURL URLWithString:yourURL];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

     (md5 encrypted)

    [request addPostValue:@"your username" forKey:@"username"];
    [request addPostValue:md5(@"your password"); forKey:@"password"];
    [request addPostValue:@"your login type" forKey:@"logintype"];
    [request setDelegate:self];
    [request startAsynchronous];
}

- (void)requestFinished:(ASIHTTPRequest *)request
{
    // Use when fetching text data
    NSString *responseString = [request responseString];

    // Use when fetching binary data
    NSData *responseData = [request responseData];
}

- (void)requestFailed:(ASIHTTPRequest *)request
{
    NSError *error = [request error];
}