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¶m2=3" http://myUrl/
it works perfect
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With