iphone - ASIHTTPRequest 问题

标签 iphone objective-c ipad asihttprequest

我知道 ASIHTTPRequest 项目已被 Ben 放弃,但无论如何,现在切换到其他项目已经太晚了,所以我决定尝试处理我遇到的问题。

我正在发布和使用 https 协议(protocol)的请求。 我已应要求禁用持久性连接。

    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];

我得到的所有信息都是 A connection failure occurred with the kCFErrorDomainCFNetwork error -1005

我已经在 ASIHTTPRequest 项目的配置中启用了所有 DEBUG 信息,并获得了以下日志

[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.)"

知道为什么会发生崩溃吗?以及如何解决这个问题?

最佳答案

几个月前我遇到了同样的问题。无法保证 Internet 连接,您会发现此错误在 3G 连接上更常见。我的解决方案是提高重试次数。在 ASIHTTPRequest.m 中将重试次数至少修改为 5,看看是否有帮助。

- (BOOL)retryUsingNewConnection
{
    if ([self retryCount] < 5) {

之所以可行,是因为在 -handleStreamError 中捕获了错误 -1005,然后在上述代码中允许多次重试连接。

关于iphone - ASIHTTPRequest 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10882697/

相关文章:

iphone - 如何阻止自定义 UITableViewCell 背景图像可拉伸(stretch)?

iPhone 中的 Android Toast?

iphone - iOS 应用程序中的触摸序列密码

ios - UIDocumentPickerViewController文件已禁用?

iphone - 在 iPhone 应用程序中旋转 MKMapView

iphone - 使用 Xcode 4.3 中地址簿中的联系人填充表格 View

iphone - 如何在不提交到应用程序商店的情况下向客户展示 iPhone 应用程序(临时分发)

iphone - 在 ios 版本高于 xcode 的 sdk 的 iphone 上测试应用程序

objective-c - 更改 JavascriptCore 中 window.localStorage 的值(从 C/Obj-C API 重新定义不可配置的属性)

iphone - 当我释放 View 时委托(delegate)崩溃,因为没有找到