我的iPhone应用程序中有用户身份验证。用户登录的工作方式是应用程序将用户名/密码发送到web服务以供用户检查。
NSString *soapMsg =
[NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>...", username, password
];
NSURL *url = [NSURL URLWithString: @"http://...Service.asmx"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://.../LoginUser" forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (conn)
{
webData = [[NSMutableData data] retain];
} 发布于 2011-07-22 15:14:56
[req setTimeoutInterval:urInterval];setTimeoutInterval:
设置接收器的超时间隔,单位为秒。
- (void)setTimeoutInterval:(NSTimeInterval)timeoutInterval
参数
timeoutInterval
超时间隔,以秒为单位。如果在连接尝试期间
该请求保持空闲的时间超过了超时间隔,则认为该请求已超时。默认的超时间隔是60秒。
发布于 2011-07-22 15:13:41
您可以使用NSURLConnection的cancel方法
/*!
@method cancel
@abstract Cancels an asynchronous load of a URL.
@discussion Once this method is called, the asynchronous load is
stopped, and the NSURLConnectionDelegate associated with the
receiver will no longer receive any asynchronous callbacks for
this NSURLConnection.
*/
- (void)cancel;发布于 2011-07-22 15:14:16
也许ASIHTTP能帮到你?
另外,如果我没理解错的话,堆栈溢出上的主要是similar issue。
https://stackoverflow.com/questions/6786761
复制相似问题