如何设置使用苹果iOS为iPad大本营凭据 [英] How do I set Basecamp credentials using apple IOS for iPad
问题描述
我想我要求公司对我们正在构建一个内部项目的Basecamp信息。我知道如何在ASP.NET环境中添加凭据,但我是新iPad的发展,似乎无法摆脱的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 ];
我补充说Bsaecamp需要像这样的HTTP标头:
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?
下面是对的Basecamp API的详细信息的链接这就解释了它需要什么: http://developer.37signals.com /大本营/
Here's a link to the Basecamp API details which explains what it needs: http://developer.37signals.com/basecamp/
帮助AP preciated。
Help appreciated.
乔
推荐答案
正如总是这样,我工作了也说不定。一旦我开始使用didReceiveAuthenticationChallenge方法事情开始陷入到位。
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];
}
然后建立一个didReceiveData方法搭上返回的数据:
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
这篇关于如何设置使用苹果iOS为iPad大本营凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!