0
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很好;在瀏覽器中,它返回我想要的。AFJsonRequest和AFHttpClient一起工作嗎?
此代碼一直工作,直到我添加了AFHTTPClient來傳遞變量。我一定在做錯事,或者我不能這樣做?