我想用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