0

The username has been encrypted via RNCryptor and I would like to send the encrypted username to server using the MKNetworkKit. The encrypted username is in NSData format. But the MKNetworkKit seems not supporting the formats for the post body except NSDictionary. So I follow the suggestion of using setCustomPostDataEncodingHandler to post the encrypted username. But it crashed. Please help review if something wrong in my below codes.

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"];
4

1 回答 1

1

尝试这个:

MKNetworkOperation *op = [self operationWithPath:INIT_URL params:body httpMethod:@"POST" ssl:YES];
[op setPostDataEncoding:MKNKPostDataEncodingTypeJSON];//This is important
[op addCompletionHandler:^(MKNetworkOperation *completedOperation)
于 2013-11-29T04:45:32.980 回答