【发布时间】:2014-07-22 15:35:44
【问题描述】:
假设这是有效的 CURL:
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;
}
【问题讨论】:
-
提供您尽最大努力提供的代码以及任何错误消息和故障描述。
-
已编辑问题,举例说明我是如何尝试的。
标签: ios objective-c afnetworking afnetworking-2