【问题标题】:NSURLConnection asynchronous call is delayed on its responseNSURLConnection 异步调用延迟响应
【发布时间】:2023-03-22 19:16:02
【问题描述】:

我正在发送一个带有异步请求的 NSURLConnection,这样我就可以取回一个 cookie,然后对那个 cookie 做一些事情。在 NewRelic 上,服务器说它正在 1 秒内处理请求。但是,当我在 iOS 端进行时间戳记时,我发现到达 completionHandler 需要 5-10 秒......有人遇到过这个吗?我已将所有其他网络带宽使用减少到零,但我仍然遇到这个问题。对其他端点的其他请求似乎很快。

因此,NewRelic 报告似乎报告该时间戳跨度内的请求仅为 400 毫秒……但就像我说的那样,我在 5000 毫秒到 10000 毫秒看到它。

想法?这是我的代码。

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
    if(response)
    {
        // code to handle with the response
        NSLog(@"timestamp after -success: %@",[NSDate date]);

        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
        if ([httpResponse respondsToSelector:@selector(allHeaderFields)]) {
            NSDictionary *fields = [(NSHTTPURLResponse *)response allHeaderFields];

           // NSString *cookie = [fields valueForKey:@"Set-Cookie"]; // It is your cookie

            NSArray * all = [NSHTTPCookie cookiesWithResponseHeaderFields:[httpResponse allHeaderFields] forURL:[NSURL URLWithString:[theUrlString stringByAddingPercentEscapesUsingEncoding:                                                                                                                            NSUTF8StringEncoding]]];

            DLog(@"%d", all.count);

            for (NSHTTPCookie *cookie in all) {
                DLog(@"Name: %@ : Value: %@", cookie.name, cookie.value);
            }
            [[WDDataController sharedInstance] resumeOperations];
            [[NSNotificationCenter defaultCenter] postNotificationName:SERVICE_AUTHENTICATED object:nil];

        }
    }
    if (error){
        NSLog(@"timestamp after error: %@",[NSDate date]);
         // code to handle with the error
         NSLog(@"Error: &@",error);
         [[WDDataController sharedInstance] resumeOperations];
    }

}];

【问题讨论】:

    标签: cookies login nsurlconnection latency newrelic


    【解决方案1】:

    我现在可以说的是 New Relic 报告的请求时间跨度是 HTTP 请求往返时间,不包括在完成处理程序中完成的任何工作。您认为 New Relic 是造成这种延迟还是应该报告更长时间的报告?

    【讨论】:

    • 所以是的,我发现发生了一个重定向,它为我提供了一个大型网站的后记。解决方案是处理重定向并从那时起更新我的 UI,而不是等待长重定向...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-29
    • 1970-01-01
    • 2016-09-03
    • 1970-01-01
    • 2016-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多