[英]Cookies handling with JSONModel/JSONHTTPClient in iOS
In my current project I am using, +(void)postJSONFromURLWithString:(NSString*)urlString params:(NSDictionary*)params completion:(JSONObjectBlock)completeBlock;
在我当前的项目中,我正在使用+(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 但是,当我更新用户个人资料(姓名,联系电话等)时,我从该语句获取响应状态代码403
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. 通常由于服务器端的授权失败而调用403。 Is there any way to see what are the cookies are going to server side while I am making an API call with 当我使用API进行调用时,有什么方法可以查看Cookie将发送到服务器端吗?
+(void)postJSONFromURLWithString:(NSString*)urlString params:(NSDictionary*)params completion:(JSONObjectBlock)completeBlock;
? ?
JSONModel's built-in networking support is intentionally very basic/primitive/limited. JSONModel的内置网络支持特意是非常基础/原始/有限的。 It does not support custom authentication, cookies, etc. 它不支持自定义身份验证,Cookie等。
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. 最好使用NSURLSession进行请求以获取数据,然后仅将JSONModel用于反序列化-而不是整个请求。
eg: 例如:
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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.