【问题标题】:Issue with ASIHTTPRequestASIHTTPRequest 的问题
【发布时间】:2012-06-04 14:06:11
【问题描述】:

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

我正在发布和使用 https 协议的请求。 我已按要求禁用了持久连接。

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

以及我通过kCFErrorDomainCFNetwork error -1005 得到的所有A connection failure occurred

我已在 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.)"

任何想法为什么会发生崩溃?以及如何解决这个问题?

【问题讨论】:

  • 请.. 添加调用此错误的代码。仅从错误很难找到问题。
  • 用代码更新帖子,但我猜这是非常标准的调用。
  • 1005 error 可能意味着您正在连接的主机已关闭连接,或者您的连接非常糟糕。主机是否有自签名证书?
  • 您可以发布您用于请求的网址吗?网址有效吗?
  • 不,我不能发布它。网址有效

标签: iphone objective-c ipad asihttprequest


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    各位,感谢您的帮助。

    我刚刚发现问题是由服务器端引起的。拒绝接受更大的数据,比如说 800K。

    非常感谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多