1
比方說,這是工作的捲曲發送十六進制字符串:作爲數據服務器使用AFNetworking 2
curl -s -d 726240786C722E6E6574FE3765653035356338636463616236323263383065353339616461643963643561 http://support.questprojects.com/portal/bukd.aspx?action=LOGIN
其中「726240786C722E6E6574FE3765653035356338636463616236323263383065353339616461643963643561」是十六進制字符串。如何使用AFNetworking 2.0做到這一點?用盡了一切辦法,但都沒有成功...
我盡力而爲:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
NSString *url = [NSString stringWithFormat:@"%@?action=LOGIN", @"http://support.questprojects.com/portal/bukd.aspx"];
NSData *postBody = [self base64DataFromString:@"726240786C722E6E6574FE3765653035356338636463616236323263383065353339616461643963643561"];
[manager POST:url parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:postBody name:@"" fileName:@"" mimeType:@""];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
- (NSData *)nsdataFromHexString: (NSString *)string
{
NSString *command = [string stringByReplacingOccurrencesOfString:@" " withString:@""];
NSMutableData *commandToSend= [[NSMutableData alloc] init];
unsigned char whole_byte;
char byte_chars[3] = {'\0','\0','\0'};
for (int i = 0; i < ([command length]/2); i++) {
byte_chars[0] = [command characterAtIndex:i*2];
byte_chars[1] = [command characterAtIndex:i*2+1];
whole_byte = strtol(byte_chars, NULL, 16);
[commandToSend appendBytes:&whole_byte length:1];
}
return commandToSend;
}
提供您盡最大努力的代碼以及任何錯誤消息和失敗的描述。 – zaph
編輯問題與我如何嘗試的例子。 – dormitkon