问题
I am making use of AFNetworking library for the first time and i have successfully implemented json parsing and it is working perfectly, now i need to make one registration page in which user will fill all the details like username, password,question,answer,name and it will post all the data on web server. I have tried with several example,however it is not posting on web server.
Below is the code for posting on web server
NSURL *baseURL = [NSURL URLWithString:@"http://apollowebservice.10summer.com/registration.php"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
[httpClient defaultValueForHeader:@"Accept"];
NSMutableDictionary *requestArray = [NSMutableDictionary new];
[requestArray setObject: @"Kashif"
forKey: @"user_name"];
[requestArray setObject: @"Kashif.jilani@triffort.com"
forKey: @"user_email"];
[requestArray setObject:@"ila@1234" forKey:@"user_password"];
[requestArray setObject:@"What is your name" forKey:@"user_question"];
[requestArray setObject:@"Kashif Answer" forKey:@"user_answer"];
[httpClient postPath:@"method" parameters:requestArray success:^(AFHTTPRequestOperation *operation, id responseObject) {
// reponseObject will hold the data returned by the server.
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error retrieving data: %@", error);
}];
回答1:
In this case you can go with a blank baseURL and have the path be
NSURL *baseURL = [NSURL URLWithString:@""];
// ...your code....
[httpClient postPath:@"http://apollowebservice.10summer.com/registration.php" parameters:requestArray success:^(AFHTTPRequestOperation *operation, id responseObject) {
// reponseObject will hold the data returned by the server.
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error retrieving data: %@", error);
}];
来源:https://stackoverflow.com/questions/13702486/how-to-post-data-on-web-server-using-afnetworking-in-iphone