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); 

im Protokoll ist die Adresse null. Das PHP ist in Ordnung; in einem Browser gibt es zurück, was ich will.Funktionieren AFJsonRequest und AFHttpClient zusammen?

Dieser Code funktionierte, bis ich den AFHTTPClient hinzugefügt habe, um eine Variable zu übergeben. Ich muss etwas falsch machen oder kann ich es nicht so machen?

Antwort

2

In Zeile 1 versuchen Sie, eine URL aus "contact.php" zu erstellen (die NSURL +URLWithString: gibt nil für zurück), wenn Sie wirklich die Basis-URL benötigen - die vollständige URL, die unter Anforderungen für eine bestimmte Webdienste, z "http://api.twitter.com/1/".