Reputation: 9875
I understand that ASIHTTPRequest project is abandoned by Ben, but anyway its too late now for me to switch to something else so I decided to try to deal with the issue I have.
I'm POSTing and a request with https protocole. I've disabled persistence connection on request.
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setUseKeychainPersistence:YES];
[request setShouldAttemptPersistentConnection:YES];
// Set the request timeout
[request setTimeOutSeconds:REQUEST_TIME_OUT];
// Upload an image
NSData *imageData = UIImagePNGRepresentation(imageContainer.mImage);
[request setPostBody:[NSMutableData dataWithData:imageData]];;
[request setDelegate:self];
[request setDidFinishSelector:@selector(uploadRequestFinished:)];
[request setDidFailSelector:@selector(uploadRequestFailed:)];
[request startAsynchronous];
And all what I'm getting A connection failure occurred
with the kCFErrorDomainCFNetwork error -1005
.
I've enabled all DEBUG info in configs of the ASIHTTPRequest
project and have got following log
[STATUS] Starting asynchronous request <ASIFormDataRequest: 0x1029e000>
[CONNECTION] Request <ASIFormDataRequest: 0x1029e000> will not use a persistent connection
[THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
[THROTTLING] ===Used: 327680 bytes of bandwidth in last measurement period===
[CONNECTION] Request attempted to use connection #(null), but it has been closed - will retry with a new connection
[CONNECTION] Request <ASIFormDataRequest: 0x1029e000> will not use a persistent connection
[THROTTLING] ===Used: 229376 bytes of bandwidth in last measurement period===
[THROTTLING] ===Used: 360448 bytes of bandwidth in last measurement period===
[CONNECTION] Request attempted to use connection #(null), but it has been closed - we have already retried with a new connection, so we must give up[STATUS] Request <ASIFormDataRequest: 0x1029e000>: Failed
[CONNECTION] Request #(null) failed and will invalidate connection #(null)ata upload failed "Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0xf624750 {NSUnderlyingError=0xf6246f0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)"
Any ideas why the crash happens ? and how to fix this ?
Upvotes: 3
Views: 1539
Reputation: 9875
Guys thanks for trying to help.
I just figured it out the problem was caused by server side. Which refused to accept data larger let say 800K.
Thanks a lot
Upvotes: 0
Reputation: 57179
I had the same issue several months ago. Internet connections are not guaranteed and you will find this error is more common on a 3G connection. My solution was to raise the retry count. Inside of ASIHTTPRequest.m
modify the retry count to at least 5 and see if that helps.
- (BOOL)retryUsingNewConnection
{
if ([self retryCount] < 5) {
The reason why this works is because error -1005
is caught in -handleStreamError
then the connection is retried as many times as allowed in the above code.
Upvotes: 2