【问题标题】:ASIHTTPRequest setDomain -> NSURLRequest equivalent?ASIHTTPRequest setDomain -> NSURLRequest 等效?
【发布时间】:2014-07-27 04:13:54
【问题描述】:

我正在尝试将一些严重依赖ASIHTTPRequest 库的旧代码转换为使用标准NSMutableURLRequest 代替。但是,我遇到了一个问题:虽然使用ASIHTTPRequest 我可以访问setDomain 函数,但我似乎找不到与NSMutableURLRequest 等效的函数。

有谁知道有没有等价的功能?我尝试将其设置为名为“域”的标题,但这似乎不起作用。

【问题讨论】:

    标签: objective-c nsurlconnection asihttprequest nsmutableurlrequest


    【解决方案1】:

    最终听从了iPhone - NTLM, Basic and other authorizations using async NSURLConnection的一些建议

    事实证明,您不必独立设置域;您可以通过将其作为用户名的一部分传递来设置它,如下所示: domain\\username 在 NSURLCredentials 对象中。我最终使用的确切代码是:

    //takes care of HTTP Authentication
    - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
        NSString* authMethod = [[challenge protectionSpace] authenticationMethod];
    
        if ([authMethod isEqualToString:NSURLAuthenticationMethodNTLM]) {
            NSURLCredential *credential = [NSURLCredential credentialWithUser:[NSString stringWithFormat:@"domain\\%@", self.userName]
                                                                     password:self.password
                                                                  persistence:NSURLCredentialPersistenceForSession];
            [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
        }
    }
    

    当然,这一切都假设班级是NSURLConnectionDeligate

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多