首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何取消web服务调用- IOS

如何取消web服务调用- IOS
EN

Stack Overflow用户
提问于 2011-07-22 15:10:02
回答 3查看 2.1K关注 0票数 0

我的iPhone应用程序中有用户身份验证。用户登录的工作方式是应用程序将用户名/密码发送到web服务以供用户检查。

代码语言:javascript
复制
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];
    }    
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-07-22 15:14:56

代码语言:javascript
复制
[req setTimeoutInterval:urInterval];

setTimeoutInterval:

设置接收器的超时间隔,单位为秒。

- (void)setTimeoutInterval:(NSTimeInterval)timeoutInterval

参数

timeoutInterval

超时间隔,以秒为单位。如果在连接尝试期间

该请求保持空闲的时间超过了超时间隔,则认为该请求已超时。默认的超时间隔是60秒。

票数 4
EN

Stack Overflow用户

发布于 2011-07-22 15:13:41

您可以使用NSURLConnection的cancel方法

代码语言:javascript
复制
/*! 
    @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;
票数 0
EN

Stack Overflow用户

发布于 2011-07-22 15:14:16

也许ASIHTTP能帮到你?

另外,如果我没理解错的话,堆栈溢出上的主要是similar issue

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6786761

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档