2012-11-28 57 views
0

用戶名已通過RNCryptor加密,我想使用MKNetworkKit將加密的用戶名發送到服務器。加密的用戶名採用NSData格式。但MKNetworkKit似乎不支持NSDictionary以外的帖子主體的格式。 所以我按照建議使用setCustomPostDataEncodingHandler發佈加密的用戶名。但它墜毀。請幫助檢查我的下面的代碼中是否有問題。如何使用MKNetworKit將AES256 NSData發佈到服務器?

NSMutableDictionary * postDataDict = [NSMutableDictionary dictionaryWithObject:username forKey:@"username"]; 


MKNetworkOperation *op = [self operationWithPath:@"URLtomyserver/login.php" 
              params:postDataDict 
              httpMethod:@"POST"]; 

[op setCustomPostDataEncodingHandler:^NSString *(NSDictionary *postDataDict) { 
    NSData * username= [postDataDict objectForKey:@"username"]; 

    NSString * postString = [[NSString alloc] initWithData:username encoding:NSUTF8StringEncoding]; 
    return postString 

} forType:@"application/json"]; 

回答

1

試試這個:

MKNetworkOperation *op = [self operationWithPath:INIT_URL params:body httpMethod:@"POST" ssl:YES]; 
[op setPostDataEncoding:MKNKPostDataEncodingTypeJSON];//This is important 
[op addCompletionHandler:^(MKNetworkOperation *completedOperation) 
相關問題