首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法将AFNetworking API发布到服务器

无法将AFNetworking API发布到服务器
EN

Stack Overflow用户
提问于 2014-01-19 17:50:31
回答 1查看 128关注 0票数 0

我试图在php中发布一个使用usercake生成的工作登记表,并且当按下按钮时,我试图向注册文件发出一个post请求。但是什么都没发生。我想我说错了什么。这是我目前的密码。

代码语言:javascript
复制
    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://thissite.co/"]];
    [httpClient setParameterEncoding:AFFormURLParameterEncoding];
    NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST"
                                                            path:@"http://thissite.co/cake/register.php?"
                                                      parameters:@{@"username":@"testingService", @"displayname":@"testingService", @"password":@"thisismypassword", @"passwordc":@"thisismypassword", @"email":@"testingservice@service.com", @"bio":@"I am this amazing bio", @"skills":@"hackingthissuckerfromaframework", @"interests":@"I like to hack", @"skills_needed":@"php anyone", @"company":@"Noneofyourtesting", @"dob":@"nopeeeee", @"occupation":@"noob"}];

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-19 19:37:05

看起来您没有执行您创建的请求。尝试在方法的末尾添加此代码。

代码语言:javascript
复制
AFHTTPRequestOperation * httpOperation = [httpClient HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
    //success code
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    //error handler
}];
[httpClient enqueueHTTPRequestOperation:httpOperation];

或者有更简单的方法

代码语言:javascript
复制
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://thissite.co/"]];
[httpClient setParameterEncoding:AFFormURLParameterEncoding];
[httpClient postPath:@"cake/register.php" parameters:@{@"username":@"testingService", ...} success:^(AFHTTPRequestOperation *operation, id responseObject) {
    //success code
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    //error handler
}];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21220390

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档