gpt4 book ai didi

iphone - 通过向 .NET Web 服务器发送 SOAP 消息来快速响应 NSUrl

转载 作者:行者123 更新时间:2023-12-03 20:09:34 24 4
gpt4 key购买 nike

我是网络服务新手。我需要从 .NET Web 服务器获取信息。为此,我使用以下代码:

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];

}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
if (data) {
NSLog(@" bcxbm,xcm,xcmcmx,b data consist %@",data);
}
else {
NSLog(@"not exist");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" message:@"<Alert message>" delegate:self cancelButtonTitle:@"Retry" otherButtonTitles:@"Cancel", nil];
[alert show];
[alert release];
}

}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{

NSLog(@"ERROR with theConenction");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);

我能够获取信息,但我需要验证它。如果没有连接,我需要触发 Alertview。为此,我有代码:

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
if (data) {
NSLog(@" bcxbm,xcm,xcmcmx,b data consist %@",data);
}
else {
NSLog(@"not exist");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" message:@"<Alert message>" delegate:self cancelButtonTitle:@"Retry" otherButtonTitles:@"Cancel", nil];
[alert show];
[alert release];
}

}

我通过删除连接进行检查。但它不会发出任何警报。一段时间后,它在控制台中显示连接错误。但这需要很多时间。除了这个还有其他的可能吗?如何在无连接时显示警报?

有人可以帮我吗?

最佳答案

connection didFailWithError: 当无法建立连接时将被调用。如果连接 didReceiveData: 被调用,则意味着您正在从 Web 服务接收某种数据。

当您删除连接时,您的代码会尝试连接到 Web 服务,并在预定义的时间间隔后超时,即调用连接 didFailWithError: 时。尝试连接需要一些时间,直到发生超时。

您甚至可以在使用 Apple 的 Reachability example 设置连接之前检查互联网连接情况。 。使用方法可以从this link查看

关于iphone - 通过向 .NET Web 服务器发送 SOAP 消息来快速响应 NSUrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4611894/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com