AFHTTPRequestOperationManager POST请求失败,网络连接丢失(-1005)

时间:2013-12-10 20:18:29

标签: ios objective-c django http-post

我的服务器端是带有DJango服务作为API的谷歌计算引擎

这是我在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];
      }];

Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost."始终失败但是当我使用curl -datacurl --data "param1=1&param2=3" http://myUrl/从终端呼叫服务时,它可以完美地运行

1 个答案:

答案 0 :(得分:1)

试试这个:

   NSURL *url = [NSURL URLWithString:BaseURLString];

而不是

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

使用

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