0

在我当前使用的项目中,+(void)postJSONFromURLWithString:(NSString*)urlString params:(NSDictionary*)params completion:(JSONObjectBlock)completeBlock;第一次创建帐户并登录我的应用程序的方法。第二次及以后,登录呼叫不存在,应用程序直接打开用户的个人资料屏幕。但是当我更新用户资料(姓名、联系电话等)时,我从语句中获得响应状态代码 403

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

在方法的实现中添加

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

403一般是因为服务器端授权失败而被调用。在我进行 API 调用时,有什么方法可以查看到服务器端的 cookie

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

4

1 回答 1

0

JSONModel 的内置网络支持故意非常基本/原始/有限。它不支持自定义身份验证、cookie 等。

您最好使用 NSURLSession 发出请求以获取数据,然后将 JSONModel 用于反序列化 - 而不是整个请求。

例如:

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];
于 2016-01-12T11:57:31.937 回答