我正在尝试启动此操作,但它甚至没有进入 NSLOG。我猜它与我的 stringUrl 相关,也许它不应该像这样工作?
这是我的代码:
NSString *stringUrl = [[NSString alloc]initWithFormat:@"http://example.com/add_user.php?username=%@&password=%@&country=%@&email=%@",[self.usernameTextField text],[self.passwordTextField text], countrySelected, [self.emailTextField text]];
NSURL *url = [NSURL URLWithString:stringUrl];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSDictionary *dict = JSON;
NSLog(@"IP Address: %@", [JSON valueForKeyPath:@"item"]);
} failure:nil];
[operation start];
编辑:这是我从失败块中得到的:
错误域=AFNetworkingErrorDomain 代码=-1016“预期的内容类型 {(“text/json”、“application/json”、“text/javascript”)},得到了 text/html”UserInfo=0xa2b4300 {NSLocalizedRecoverySuggestion={“type”: "1","item": "用户添加成功。"} , AFNetworkingOperationFailingURLRequestErrorKey=http://EXAMPLE.com/add_user.php?username=aaasafasfasf&password=aaa&country=Angola&email=aaaasfasfasfasfasf>, NSErrorFailingURLKey= http://EXAMPLE.com /add_user.php?username=aaasafasfasf&password=aaa&country=Angola&email=aaaasfasfasfasfasf , NSLocalizedDescription=预期的内容类型 {( "text/json", "application/json", "text/javascript" )}, 得到 text/html,AFNetworkingOperationFailingURLResponseErrorKey=}