我想用AFNetworking做一个包含GET和POST参数的POST请求。iOS AFNetworking GET/POST参数
我使用这个代码:
NSString *urlString = [NSString stringWithFormat:@"upload_stuff.php?userGUID=%@&clientGUID=%@",
@"1234",
[[UIDevice currentDevice] identifierForVendor].UUIDString];
NSString *newUrl = @"https://sub.domain.com";
NSURL *baseURL = [NSURL URLWithString:newUrl];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
[httpClient defaultValueForHeader:@"Accept"];
NSDictionary *getParams = [NSDictionary dictionaryWithObjectsAndKeys:
@"1234", @"userGUID",
[[UIDevice currentDevice] identifierForVendor].UUIDString, @"clientGUID",
nil];
NSDictionary *postParams = [NSDictionary dictionaryWithObjectsAndKeys:
[@"xyz" dataUsingEncoding:NSUTF8StringEncoding], @"FILE",
nil];
[httpClient postPath:urlString parameters:postParams success:^(AFHTTPRequestOperation *operation, id responseObject) {
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error retrieving data: %@", error);
}];
现在我有两个问题:
我如何可以同时使用在相同的请求GET和POST词典?目前,我正在将GET字典集成到URL中,并仅使用POST字典(
[httpClient postPath:...]
)我收到服务器错误,指出参数“FILE”丢失。不幸的是,我无法检查任何服务器日志(不是我的服务器)。但使用标准
NSURLConnection
我能够发送请求与FILE
参数到此服务器。那么这里出了什么问题?
Afnetworking有自己的发送文件的方法 – Horst 2013-03-25 03:32:03
你可以给任何代码吗? – 2013-03-25 11:19:25