0

In my current project I am using, +(void)postJSONFromURLWithString:(NSString*)urlString params:(NSDictionary*)params completion:(JSONObjectBlock)completeBlock; method to create account and log in my application for the very first time . For second time and onwards, log in call is not there, application directly opens the user's profile screen. But when I am updating user profile (name, contact number etc.), I am getting response status code 403 from by the statement

NSLog(@"Response status code = %i", (int)response.statusCode);

added in implementation of method

+(NSData*)syncRequestDataFromURL:(NSURL*)url method:(NSString*)method requestBody:(NSData*)bodyData headers:(NSDictionary*)headers etag:(NSString**)etag error:(JSONModelError**)err

403 is generally invoked due to authorization failure in server side. Is there any way to see what are the cookies are going to server side while I am making an API call with

+(void)postJSONFromURLWithString:(NSString*)urlString params:(NSDictionary*)params completion:(JSONObjectBlock)completeBlock;?

Sauvik Dolui
  • 5,520
  • 3
  • 34
  • 44

1 Answers1

0

JSONModel's built-in networking support is intentionally very basic/primitive/limited. It does not support custom authentication, cookies, etc.

You'd be best making a request with NSURLSession to get the data, then use JSONModel just for the deserialization - rather than for the whole request.

e.g.:

NSURLSession *session = [NSURLSession sharedSession];
NSURL *url = [NSURL URLWithString:@"https://example.com/mydata.json"];

NSURLSessionDataTask *task = [session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    MyModel *obj = [[MyModel alloc] initWithData:data error:nil];
}];

[task resume];
James Billingham
  • 760
  • 8
  • 32