如何在iPhone中使用AFNetWorking在Web服务器上发布数据 [英] How to Post data on web server using AFNetWorking in iPhone

查看:263
本文介绍了如何在iPhone中使用AFNetWorking在Web服务器上发布数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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


推荐答案

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

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

这篇关于如何在iPhone中使用AFNetWorking在Web服务器上发布数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆