如何在iPhone中使用AFNetWorking在Web服务器上发布数据

时间:2012-12-04 12:05:14

标签: iphone web-services afnetworking

我第一次使用AFNetworking库并且我已经成功实现了json解析并且它工作正常,现在我需要创建一个注册页面,其中用户将填写所有详细信息,如用户名,密码,问题,回答,名称,它将在Web服务器上发布所有数据。我尝试了几个例子,但它没有发布在Web服务器上。

以下是在网络服务器上发布的代码

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 个答案:

答案 0 :(得分:0)

在这种情况下,您可以使用空白baseURL并使路径为

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);
}];