您好我正在使用ASIHTTPRequest POST在basecamp上为登录用户添加时间条目。 但
- (void)request:(ASIHTTPRequest *)request didReceiveResponseHeaders:(NSDictionary *)responseHeaders
- (void)requestFailed:(ASIHTTPRequest *)request
我因访问被拒绝而收到错误。
我还需要向basecamp URl发送身份验证令牌,请帮我解决这个问题。
NSString *postData=[NSString stringWithFormat: @"<time-entry>\
<person-id> 898989 </person-id>\
<date>2011-04-07</date>\
<hours>2:00</hours>\
<description>test</description>\
</time-entry>"];
NSURL *url = [NSURL URLWithString:@"https://test.basecamphq.com/projects/4644/time_entries.xml"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setDelegate:self];
[request setRequestMethod:@"POST"];
[request appendPostData:[postData dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]];
[request addRequestHeader:@"Accept" value:@"application/xml"];
[request addRequestHeader:@"Content-Type" value:@"application/xml"];
[request authenticationNeeded];
[request setValidatesSecureCertificate:NO];
[request startAsynchronous];
这是我的代码。请帮忙。
答案 0 :(得分:0)
假设这是正确的API文档:
http://developer.37signals.com/basecamp/
然后使用HTTP基本身份验证进行basecamp,这意味着你需要这样做:
[request setAuthenticationScheme:(NSString *)kCFHTTPAuthenticationSchemeBasic]; [request setUsername:yourApiToken]; [请求setPassword:@“X”];
将您的API令牌放在“yourApiToken”的位置。