我正在尝试发布使用usercake制作的php中的工作注册表单,并且当按下按钮时我试图向注册文件发出帖子请求。但没有任何反应。我相信我写错了。这是我目前的代码。
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"}];
}
答案 0 :(得分:0)
看起来您没有执行您创建的请求。尝试在方法结束时添加此代码。
AFHTTPRequestOperation * httpOperation = [httpClient HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
//success code
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//error handler
}];
[httpClient enqueueHTTPRequestOperation:httpOperation];
或者有一种更简单的方法
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
}];