【问题标题】:How to use Asihttprequest asynchronous requests server?如何使用 Asihttprequest 异步请求服务器?
【发布时间】:2014-11-18 06:02:33
【问题描述】:

我的服务器登录参数:

username
password (md5 encrypted)
logintype

返回参数:

userId
username
levelid
mobilenum
email
  • 0 成功
  • 10001 账户名不能为空
  • 10002 账号不存在
  • 10003密码不正确
  • 10004 帐号无效

【问题讨论】:

  • MD5 不是加密,它是一个哈希函数。它不是加密,因为它是一种精细的函数,即给定一个散列无法获得原始数据。请做一些研究。

标签: ios httprequest asihttprequest sendasynchronousrequest


【解决方案1】:

试试这个,

#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];
}

【讨论】:

  • ASIHTTP 真的不应该用于新工作。来自ASIHTTPRequest page:“请注意,我不再在这个库上工作——你可能想考虑为新项目使用其他东西。:)”当前最喜欢的库是AFNetworking
猜你喜欢
  • 2018-06-23
  • 2012-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-05
  • 1970-01-01
相关资源
最近更新 更多