【发布时间】:2013-03-24 22:48:07
【问题描述】:
我想使用包含 GET 和 POST 参数的 AFNetworking 发出 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 有自己的文件发送方法
-
你能给出任何代码吗?
标签: ios nsurlconnection afnetworking