0

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);
}
Vladimir Stazhilov
  • 1,873
  • 4
  • 29
  • 60
  • and how does the console-output look like? – thomas Jan 14 '12 at 15:01
  • See the following [stackoverflow link](http://stackoverflow.com/questions/4456966/how-to-send-json-data-in-the-http-request-using-nsurlrequest). Hope it helps. – Lorenzo B Jan 14 '12 at 15:02
  • doesn't matter how it will look like because because it's a fake URL from a tutorial. Thanks, Flex_Addicted, you're helping me the second time today – Vladimir Stazhilov Jan 14 '12 at 15:05

0 Answers0