2012-04-07 3 views
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); 

로그에서 주소는 null입니다. PHP는 괜찮습니다. 브라우저에서, 그것은 내가 원하는 것을 반환합니다.AFJsonRequest와 AFHttpClient가 함께 작동합니까?

이 코드는 변수에 전달할 AFHTTPClient를 추가 할 때까지 작동했습니다. 나는 틀린 일을해야하거나 그렇지 않을 수 있습니까?

답변

2

온라인에서 1 번은 실제 필요한 URL이 'contact.php'(NSURL +URLWithString:이 을 반환)에서 URL을 만들려고합니다. 기본 URL은 URL에 대한 요청 중에서 공통적 인 전체 URL입니다. 특정 웹 서비스, 예. "http://api.twitter.com/1/".

관련 문제