问题描述
我正在通过 RestKit 发送一个 objectManager postObject 调用.在返回 403 的 4 次尝试之后,我的第 5 次尝试没有被 RestKit 接收和发送.我已经使用 Charles 观察我的实际流量验证了这一点,并且通过查看 RestKit 日志,RestKit 正在获取我的请求并将其放入 RequestQueue,但它从未被撤回.
I'm sending an objectManager postObject call through RestKit. After 4 attempts that return 403's my 5th attempt isn't picked up and sent out by RestKit. I've verified this using Charles to watch my actual traffic, and by reviewing the RestKit logs, RestKit is getting my request and putting it in the RequestQueue, but it's never taken back out.
我的前 4 个请求在 RestKit 日志中看起来像这样(为日志墙道歉):
My first 4 requests look like this in the RestKit logs (apologies for the wall of log):
D restkit:RKObjectManager.m:171 CacheTimeoutSet: 60.000000 - 60.000000
T restkit.network.queue:RKRequestQueue.m:226 Request <RKObjectLoader: 0x784ac90> added to queue <RKRequestQueue: 0x6501530>
T restkit.network.queue:RKRequestQueue.m:173 Processing request <RKObjectLoader: 0x784ac90> in queue <RKRequestQueue: 0x6501530>
T restkit.network.queue:RKRequestQueue.m:104 Loading count increasing from 0 to 1. Firing requestQueueDidBeginLoading
T restkit.network.queue:RKRequestQueue.m:131 Loading count set to 1 for queue <RKRequestQueue: 0x6501530>
T restkit.network.cache:RKRequestCache.m:106 Found cachePath '<REMOVED>' for <RKObjectLoader: 0x784ac90>
T restkit.network.cache:RKRequestCache.m:123 Determined hasResponseForRequest: <RKObjectLoader: 0x784ac90> => NO
D restkit.network:RKRequest.m:255 Sending asynchronous POST request to URL <REMOVED>.
D restkit.network:RKObjectLoader.m:295 POST or PUT request for source object <TSLAuthenticationContract: 0x7849b30>
Username:<REMOVED>
Campus:<REMOVED>, serializing to MIME Type application/json for transport...
D restkit.object_mapping:RKObjectMappingOperation.m:391 Starting mapping operation...
T restkit.object_mapping:RKObjectMappingOperation.m:231 Mapping attribute value keyPath 'username' to 'Username'
T restkit.object_mapping:RKObjectMappingOperation.m:241 Mapped attribute value from keyPath 'username' to 'Username'. Value: <REMOVED>
T restkit.object_mapping:RKObjectMappingOperation.m:231 Mapping attribute value keyPath 'password' to 'Password'
T restkit.object_mapping:RKObjectMappingOperation.m:241 Mapped attribute value from keyPath 'password' to 'Password'. Value: <REMOVED>
T restkit.object_mapping:RKObjectMappingOperation.m:231 Mapping attribute value keyPath 'campusName' to 'CampusName'
T restkit.object_mapping:RKObjectMappingOperation.m:241 Mapped attribute value from keyPath 'campusName' to 'CampusName'. Value: <REMOVED>
D restkit.object_mapping:RKObjectMappingOperation.m:397 Finished mapping operation successfully...
T restkit.network.cache:RKRequestCache.m:106 Found cachePath '<REMOVED>' for <RKObjectLoader: 0x784ac90>
D restkit.network.cache:RKRequestCache.m:220 Read nil cached headers from cachePath '<REMOVED>' for '<RKObjectLoader: 0x784ac90>'
D restkit.network.cache:RKRequestCache.m:245 Found cached ETag '(null)' for '<RKObjectLoader: 0x784ac90>'
T restkit.network:RKRequest.m:209 Prepared POST URLRequest '<NSMutableURLRequest <REMOVED>>'. HTTP Headers: <REMOVED>.
D restkit.network.queue:RKRequestQueue.m:180 Sent request <RKObjectLoader: 0x784ac90> from queue <RKRequestQueue: 0x6501530>. Loading count = 1 of 4
T restkit.network.queue:RKRequestQueue.m:142 Timer initialized with delay 0.300000 for queue <RKRequestQueue: 0x6501530>
<REMOVED - Multiple Timer messages>
T restkit.network.queue:RKRequestQueue.m:142 Timer initialized with delay 0.300000 for queue <RKRequestQueue: 0x6501530>
D restkit.network:RKResponse.m:105 NSHTTPURLResponse Status Code: 403
然而,在我第 5 次通话时发生了这种情况:
However, on my 5th call this happens:
D restkit:RKObjectManager.m:171 CacheTimeoutSet: 60.000000 - 60.000000
T restkit.network.queue:RKRequestQueue.m:226 Request <RKObjectLoader: 0x782a370> added to queue <RKRequestQueue: 0x6501530>
T restkit.network.queue:RKRequestQueue.m:142 Timer initialized with delay 0.300000 for queue <RKRequestQueue: 0x6501530>
<REMOVED - Multiple Timer messages>
T restkit.network.queue:RKRequestQueue.m:142 Timer initialized with delay 0.300000 for queue <RKRequestQueue: 0x6501530>
如您所见,没有处理请求日志,没有加载计数日志,将请求添加到队列后什么也没有.有谁之前经历过这个吗?是否有一些内部计数器阻止 RestKit 再次进行此调用?我的用户技术水平不高,而且密码有问题,因此他们连续 4 次无法通过身份验证并非不可想象.
As you can see, no Processing request log, no Loading count log, nothing after adding the request to the queue. Has anyone experienced this before? Is there some internal counter that is preventing RestKit from making this call again? I have users that aren't very technical and have issues with there passwords and so it's not inconceivable that they could fail to authenticate more than 4 times in a row.
经过更多研究,似乎 RestKit 在收到失败响应时并没有减少 objectLoader 中的 loadingCount 标志.不幸的是,我不确定我应该如何解决这个问题.是否像检查我的委托中的 403 并在找到时手动删除请求一样简单?
After more research it appears that RestKit isn't decrementing the loadingCount flag in the objectLoader when it gets a failed response. Unfortunately I'm not sure how I should go about fixing this. Is it as simple as checking for the 403 in my delegate and removing the request manually if I find it?
编辑 2:好的,我能够通过在我的 objectLoader:didFailWithError: 委托方法中调用 RKRequestQueue cancelRequest: 来强制删除失败的请求.不确定这是否是正确的方法,但它有效.我希望 RestKit 在内部处理这个问题.
EDIT 2:Ok, I was able to force the removal of the failed request by calling RKRequestQueue cancelRequest: in my objectLoader:didFailWithError: delegate method. Not sure if this is the correct way, but it works. I would expect that RestKit internally handled this issue.
谢谢,罗布
推荐答案
我将我的解决方案编辑到我的问题中,但为了让这里感到高兴,它再次被接受了.
I put my solution in edits to my question, but to make SO happy here it is again in an accepted answer.
经过更多研究,RestKit 似乎并没有减少当得到一个失败的响应时,objectLoader 中的 loadingCount 标志.不幸的是,我不确定我应该如何解决这个问题.是不是作为就像检查我的委托中的 403 并删除请求一样简单如果我找到它,请手动?
好的,我能够强制删除失败的请求调用 RKRequestQueue cancelRequest: 在我的objectLoader:didFailWithError: 委托方法.不确定这是不是正确的方法,但它有效.我希望在内部使用 RestKit处理了这个问题.
Ok, I was able to force the removal of the failed request by calling RKRequestQueue cancelRequest: in my objectLoader:didFailWithError: delegate method. Not sure if this is the correct way, but it works. I would expect that RestKit internally handled this issue.
这篇关于未发送连续第 5 次 RestKit 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!