iOS:使用ASIHTTPRequest时随机获取“发生连接失败”

时间:2012-03-18 22:21:35

标签: iphone ios asihttprequest

我正在使用ASIHTTPRequest访问我在Amazon EC2上托管的Web服务。它在98%的时间内工作得很好,但偶尔它会挂起一段时间并最终调用didFail选择器并显示错误消息“发生连接失败”。如果我然后立即重新提交请求它会很好。什么可能导致这种行为?虽然我喜欢这个库,如果我无法解决这个问题,我可能需要将所有内容还原为NSURLConnection,我宁愿不这样做。

我应该注意,我呼叫的所有网址都是https。

这是我用来创建所有请求对象的辅助方法:

-(ASIHTTPRequest*) createAPIRequest:(NSString*)_url post:(BOOL)_post {

    //encode the url
    NSURL *url = [NSURL URLWithString:_url];

    //create the right kind of request object
    ASIHTTPRequest *request;
    if (_post) {
        request = [ASIFormDataRequest requestWithURL:url];        
        [(ASIFormDataRequest*)request setPostValue:apiKey forKey:@"api_key"];
    } else {
        request = [ASIHTTPRequest requestWithURL:url];
    }

    //set the default values that all requests have
    [request setValidatesSecureCertificate:NO];
    [request setDelegate:self];
    [request setDidFinishSelector:@selector(requestDone:)];
    [request setDidFailSelector:@selector(requestWentWrong:)];
    [request setTimeOutSeconds:60];
    [request setShouldAttemptPersistentConnection:NO];

    return request;
}

我还应该注意,似乎有一个类似的问题here。但是,该问题似乎已于2011年9月修复,我使用的是2011-09-19 v1.8.1-61。我也将shouldAttemptPersistentConnection设置为NO,以防万一,仍然会出现奇怪的行为。

编辑:这是ASIHTTPRequest挂断时的日志。

2012-03-18 16:13:30:725 myApp[1735:74243] -[myAppAPI apiSetAlert:alertObject:] [Line 695] Attempting connection to http://api.t.myapp.com/1/devices/A4FA78A8-2BCB-49CD-BEE8-70ADA02156F9
2012-03-18 16:13:30:730 myApp[1735:105479] -[ASIFormDataRequest buildPostBody] [Line 211] 
==== Building an application/x-www-form-urlencoded body ====
api_key=123&a=123&b=1&c=31&d=1
==== End of application/x-www-form-urlencoded body ====

2012-03-18 16:13:30:733 myApp[1735:105479] -[ASIHTTPRequest startRequest] [Line 1374] [CONNECTION] Request <ASIFormDataRequest: 0x6993800> will not use a persistent connection
2012-03-18 16:13:31:488 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 46 bytes of bandwidth in last measurement period===
2012-03-18 16:13:32:738 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:33:988 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:35:238 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:36:488 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:37:737 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:38:987 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:40:237 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:41:487 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:42:737 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:43:987 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:45:237 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:46:487 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:47:737 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:48:986 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:50:237 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:51:487 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:52:737 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:53:987 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:55:236 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:56:487 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:57:736 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:13:58:986 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:00:238 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:01:487 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:02:737 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:03:986 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:05:236 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:06:485 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:07:735 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:08:986 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:10:235 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:11:485 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:12:736 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:13:985 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:15:235 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:16:485 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:17:735 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:18:985 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:20:235 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:21:485 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:22:736 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:23:985 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:25:234 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:26:484 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:27:735 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:28:987 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:30:235 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:31:484 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:32:734 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:35:234 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:36:484 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:37:734 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:38:983 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:40:234 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:41:484 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:42:734 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:43:984 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:45:233 myApp[1735:105479] +[ASIHTTPRequest recordBandwidthUsage] [Line 4559] [THROTTLING] ===Used: 0 bytes of bandwidth in last measurement period===
2012-03-18 16:14:46:478 myApp[1735:105479] -[ASIHTTPRequest failWithError:] [Line 2075] [STATUS] Request <ASIFormDataRequest: 0x6993800>: Failed
2012-03-18 16:14:46:480 myApp[1735:105479] -[ASIHTTPRequest failWithError:] [Line 2083] [CONNECTION] Request #(null) failed and will invalidate connection #(null)
2012-03-18 16:14:46:483 myApp[1735:74243] -[myAppAPI requestWentWrong:] [Line 79] requestWentWrong: 0 - A connection failure occurred

0 个答案:

没有答案