NSMutableURLRequest not obeying my timeoutInterval

前端 未结 3 495
野性不改
野性不改 2020-11-29 20:28

I\'m POST\'ing a small image, so i\'d like the timeout interval to be short. If the image doesn\'t send in a few seconds, it\'s probably never going to send. For some unknow

3条回答
  •  日久生厌
    2020-11-29 21:14

    There's a thread on Apple dev forums discussing this issue. Apparently on iPhone OS, the setter mandates timeoutInterval a minimum of 240 seconds (4 minutes). This only occurs when the postBody is not empty (typically when using a POST request). This seems crazy, but apparently it's there to make sure requests leave the system even though it might take many seconds for the WWAN (3G) interface to wake up. 240 seconds seems rather steep, so they suggest to set a timer and cancel the asynchronous connection when your timer fires. I know this seems stupid, but that's the only I managed to get timeout for POST requests... :-(

提交回复
热议问题