用户名已通过RNCryptor加密,我想使用MKNetworkKit将加密的用户名发送到服务器。加密的用户名是NSData格式。但是除了NSDictionary之外,MKNetworkKit似乎不支持帖子体的格式。 所以我遵循使用setCustomPostDataEncodingHandler发布加密用户名的建议。但它崩溃了。如果我的下面的代码有问题,请帮忙检查一下。
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"];
答案 0 :(得分:1)
试试这个:
MKNetworkOperation *op = [self operationWithPath:INIT_URL params:body httpMethod:@"POST" ssl:YES];
[op setPostDataEncoding:MKNKPostDataEncodingTypeJSON];//This is important
[op addCompletionHandler:^(MKNetworkOperation *completedOperation)