0

I have a REST service running on a local apache server. I am trying to send a http request to trigger it from an ios application. I have tried in numerous ways but the request doesn't seem to reach the server.

EDIT: The REST service decides what to call based on a specific MIME type, that's why I'm setting the content-type.

This is what I have at the moment for code:

- (IBAction)fetchTweet
{
    NSURL *url = [NSURL URLWithString:@"http://127.0.0.1:8080/Jersey/rest/hello"];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

    [request addValue:@"text/html; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];

    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request     delegate:self];

    self.connection = connection;
    [connection start];

}


- (IBAction)go:(id)sender
{
    [self fetchTweet];
    self.label.text = @"Working";
}
user3461851
  • 45
  • 12

1 Answers1

0

This is a synchronous request. Try using the below code to this the server synchronously. At least this will make sure everything is running fine. responseData can be written in a file to see the response.

NSURL *url = [NSURL URLWithString:@"http://127.0.0.1:8080/Jersey/rest/hello"];

NSURLResponse *urlResponse = nil;
NSData *responseData = nil;

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"GET"];
[request addValue:@"text/html; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];

responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&theError];