I want to send a string like @"projects 02.03.2012" to the backend and receive back a json response with list of projects selected according to the string I send. The back end will be done for me, but I wonder how the request url should look like and whether I will receive proper response. Here is what I've got so far, the request url is just for test.
-(void)requestProjects
{
responseData=[[NSMutableData alloc] init];
responseArray=[[NSMutableArray alloc] init];
NSURLRequest *request = [NSURLRequest requestWithURL:
[NSURL URLWithString:@"http://search.twitter.com/search.json?q=mobtuts&rpp=5"]];
NSURLConnection *connection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
}
#pragma mark NSURLConnection delegate methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"Connection failed!");
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSDictionary *results = [responseString JSONValue];
NSLog(@"Response: %@", results);
}