NSURL *url = [NSURL URLWithString:@"contact.php"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"companyID", constCompanyID,
nil];
NSURLRequest *request = [httpClient requestWithMethod: @"POST" path:@"contact.php" parameters:params];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
for(id entry in JSON)
{
self.strAddr = [entry valueForKeyPath:@"addr"];
CCLOG(@"Address: %@", self.strAddr);
}
} failure:nil];
[operation start];
CCLOG(@"Address: %@", strAddr);
在日志中,地址为空。PHP很好;在浏览器中,它返回我想要的。
在我添加 AFHTTPClient 以传入变量之前,此代码一直有效。我一定是做错了什么,或者我不能那样做吗?