How to Post data on web server using AFNetWorking in iPhone [closed]

亡梦爱人 提交于 2019-12-13 09:07:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!