Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AFHTTPRequestOperationManager POST request fails with network connection was lost (-1005)

my server side is google compute engine with DJango services as API

this is the code I'm running in xcode IOS 6.1

static NSString *const BaseURLString = @"http://myUrl/";

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager POST:BaseURLString
   parameters:[self getParameters]
      success:^(AFHTTPRequestOperation *operation, id responseObject) {
          NSArray *returnedData = (NSArray *)responseObject;
          [self doSomething:returnedData];
      }
      failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Properties" message:[NSString stringWithFormat:@"%@", error] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
          [av show];
      }];

It always fails with Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." but when I call the service from the terminal using curl -datacurl --data "param1=1&param2=3" http://myUrl/ it works perfect

like image 600
liv a Avatar asked Nov 11 '22 16:11

liv a


1 Answers

Try this:

   NSURL *url = [NSURL URLWithString:BaseURLString];

and instead of

   [manager POST:BaseURLString parameters:[self getParameters]
  success:^(AFHTTPRequestOperation *operation, id responseObject) {
      NSArray *returnedData = (NSArray *)responseObject;
      [self doSomething:returnedData];

use

   [manager POST:url parameters:[self getParameters]
  success:^(AFHTTPRequestOperation *operation, id responseObject) {
      NSArray *returnedData = (NSArray *)responseObject;
      [self doSomething:returnedData];
like image 60
RJiryes Avatar answered Nov 15 '22 06:11

RJiryes