如何使用适用于 iPad 的 Apple IOS 设置 Basecamp 凭据

发布于 2024-09-27 06:02:18 字数 1246 浏览 4 评论 0原文

我正在尝试请求我公司的 Basecamp 信息来了解我们正在构建的内部项目。我了解如何在 ASP.NET 环境中添加凭据,但我是 iPad 开发新手,似乎无法从 Basecamp 获得适当的响应。这就是我正在做的:

NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mybasecampname.basecamphq.com/projects.xml"]
                                             cachePolicy:NSURLRequestUseProtocolCachePolicy
                                          timeoutInterval:60.0 ];

我正在添加 Bsaecamp 所需的 HTTP 标头,如下所示:

[theRequest setValue:@"application/xml" forHTTPHeaderField:@"Content-Type" ];
    [theRequest setValue:@"application/xml" forHTTPHeaderField:@"Accept" ];

我知道我还需要发送我的凭据以进行身份​​验证 - 我的身份验证令牌和我喜欢的任何密码,但我不确定最好的方法来做到这一点。这就是我正在尝试的:

NSURLCredential *credential = [NSURLCredential credentialWithUser:@"MY TOKEN HERE"
                                                             password:@"x"
                                                persistence:NSURLCredentialPersistenceForSession];

我的问题是:我是否走在正确的轨道上,还是我完全错过了一些东西?

以下是 Basecamp API 详细信息的链接,其中解释了它的需求: http://developer.37signals.com/basecamp/

帮助表示赞赏。

I'm trying to request my company's Basecamp info for an internal project we're building. I understand how to add credentials in an ASP.NET environment but I'm new to iPad development and can't seem to get an appropriate response from Basecamp. Here's what I'm doing:

NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mybasecampname.basecamphq.com/projects.xml"]
                                             cachePolicy:NSURLRequestUseProtocolCachePolicy
                                          timeoutInterval:60.0 ];

I'm adding the HTTP headers that Bsaecamp requires like so:

[theRequest setValue:@"application/xml" forHTTPHeaderField:@"Content-Type" ];
    [theRequest setValue:@"application/xml" forHTTPHeaderField:@"Accept" ];

I know I also need to send my credentials for authentication purposes - my authentication token and any password I like but I'm not sure the best way to do this. Here's what I'm trying:

NSURLCredential *credential = [NSURLCredential credentialWithUser:@"MY TOKEN HERE"
                                                             password:@"x"
                                                persistence:NSURLCredentialPersistenceForSession];

My question is: Am I on the right track here or am I missing something completely?

Here's a link to the Basecamp API details which explains what it needs: http://developer.37signals.com/basecamp/

Help appreciated.

Joe

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你没皮卡萌 2024-10-04 06:02:18

一如既往,我最终解决了这个问题。一旦我开始使用 didReceiveAuthenticationChallenge 方法,事情就开始步入正轨。

所以。我简化了我的请求方法:

- (void)startRequest
{
    NSURL *url = [NSURL URLWithString:@"http://mybasecampproject.basecamphq.com/projects.xml"];
    NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];

    // Start the connection request
    urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];

    }

然后设置一个用于接收身份验证质询的方法:

- (void)connection:(NSURLConnection *)connection 
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
    NSLog(@"Authentication challenge..."); 

    NSURLCredential *cred = [[[NSURLCredential alloc] initWithUser:@"my basecamp token here" password:@"X"
                                                           persistence:NSURLCredentialPersistenceForSession] autorelease];
        [[challenge sender] useCredential:cred forAuthenticationChallenge:challenge];

}

然后设置一个 didReceiveData 方法来捕获返回的数据:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    NSLog(@"Did receive data"); 

    NSString * strResult = [[NSString alloc] initWithData: data encoding:NSUTF8StringEncoding];
    NSLog(strResult);
}

希望这对其他人有帮助。

仍然很高兴听到这个

JJ有更好的方法

As is always the way, I worked it out eventually. Once I started using the didReceiveAuthenticationChallenge method things started to fall into place.

So. I simplified my request method:

- (void)startRequest
{
    NSURL *url = [NSURL URLWithString:@"http://mybasecampproject.basecamphq.com/projects.xml"];
    NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];

    // Start the connection request
    urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];

    }

and then set up a method for receiving the authentication challenge:

- (void)connection:(NSURLConnection *)connection 
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
    NSLog(@"Authentication challenge..."); 

    NSURLCredential *cred = [[[NSURLCredential alloc] initWithUser:@"my basecamp token here" password:@"X"
                                                           persistence:NSURLCredentialPersistenceForSession] autorelease];
        [[challenge sender] useCredential:cred forAuthenticationChallenge:challenge];

}

then set up a didReceiveData method to catch the data returned:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    NSLog(@"Did receive data"); 

    NSString * strResult = [[NSString alloc] initWithData: data encoding:NSUTF8StringEncoding];
    NSLog(strResult);
}

Hope this helps someone else out there.

Still happy to hear better method for this

JJ

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文