如何使用apple IOS for iPad设置Basecamp凭据
我正试图为我们正在建设的一个内部项目请求我公司的大本营信息。我知道如何在ASP.NET环境中添加凭据,但我对iPad开发还不熟悉,似乎无法从Basecamp获得适当的响应。以下是我正在做的:如何使用apple IOS for iPad设置Basecamp凭据,ios,ipad,authentication,basecamp,Ios,Ipad,Authentication,Basecamp,我正试图为我们正在建设的一个内部项目请求我公司的大本营信息。我知道如何在ASP.NET环境中添加凭据,但我对iPad开发还不熟悉,似乎无法从Basecamp获得适当的响应。以下是我正在做的: NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mybasecampname.basecamphq.com/projects.xml"]
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详细信息的链接,解释了它需要什么:
谢谢你的帮助
乔像往常一样,我最终解决了这个问题。一旦我开始使用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