一旦我向服务器发送请求(通过NSURLConnection
sendSynchronousRequest
方法),服务器会在大约 2 秒内收到它,它会在另外 3-5 秒内处理并发送回响应。但是,我只能在 30-35 秒内得到回复。这种延迟使我们的沟通非常缓慢。
甚至异步 API 也得到了延迟响应。
早些时候,一切正常,客户端在 10 秒内得到响应。还有谁有相同的问题吗?可能是什么原因?
编辑
这里是Wireshark
分析的截图:
链接到更好的图像
我应该如何查看哪个数据包在说什么?...为什么会延迟?
EDIT2 这是代码:
NSHTTPURLResponse *response=nil;
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:nsURL] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:180.0];
[theRequest setHTTPMethod:@"POST"];
[theRequest setTimeoutInterval:180.0];
[theRequest setHTTPBody:[[NSString stringWithFormat:@"%@",sdata] dataUsingEncoding:NSASCIIStringEncoding]];
NSError *error= nil;
NSData *result = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
if (error ) {
NSLog(@"error sending synchronous request: %@", error);
}
NSLog(@"request completed with code:%d",response.statusCode);