-1

我第一次使用 AFNetworking 库,我已经成功实现了 json 解析,它运行良好,现在我需要创建一个注册页面,用户将在其中填写所有详细信息,如用户名、密码、问题、答案、名称它会将所有数据发布到网络服务器上。我试过几个例子,但它没有发布在网络服务器上。

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

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

1 回答 1

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);
}];
于 2012-12-04T12:52:27.777 回答