user3675069
user3675069

Reputation: 53

How to send request, by using RESTFul web services?

I have sucessfully received value from http://rest-service.guides.spring.io/greeting by using RESTFul and json web services. But unable to send my own text box value in request to my own server running apache on another machine.

my working code -:

- (IBAction)fetchGreeting;
{
    NSURL *url = [NSURL URLWithString:@"http://rest-service.guides.spring.io/greeting"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [NSURLConnection sendAsynchronousRequest:request
                                       queue:[NSOperationQueue mainQueue]
                           completionHandler:^(NSURLResponse *response,
                                               NSData *data, NSError *connectionError)
     {
         if (data.length > 0 && connectionError == nil)
         {
             NSDictionary *greeting = [NSJSONSerialization JSONObjectWithData:data
                                                                      options:0
                                                                        error:NULL];
             self.greetingId.text = [[greeting objectForKey:@"id"] stringValue];
             self.greetingContent.text = [greeting objectForKey:@"content"];
         }
     }];
}

But it stop working when i change NSURL *url = [NSURL URLWithString:@"http://rest-service.guides.spring.io/greeting"]; value to my own server address, and also unable to wrap my own text box value in request.

Upvotes: 0

Views: 336

Answers (1)

Sangeetha
Sangeetha

Reputation: 46

We usually add our textfield data into the request like this.

NSString *url =[NSString stringWithFormat:@"http://rest-service.guides.spring.io/greeting/%@",textFied.text];

Can you show how your URL look like?

Upvotes: 1

Related Questions