嗨,我正在使用ASIHTTPRequest POST为登录用户添加basecamp上的时间条目。但
- (void)request:(ASIHTTPRequest *)request didReceiveResponseHeaders:(NSDictionary *)responseHeaders
ASIHTTPRequest的方法正在被调用,并且在
- (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]; 这是我的代码。请帮帮忙。
发布于 2011-07-07 20:59:46
假设这是正确的API文档:
http://developer.37signals.com/basecamp/
然后使用HTTP基本身份验证进行基本验证,这意味着您需要执行以下操作:
请求setAuthenticationScheme:(NSString *)kCFHTTPAuthenticationSchemeBasic;请求setUsername:yourApiToken;请求setPassword:@"X";
将您的API令牌放在它显示为“yourApiToken”的位置。
https://stackoverflow.com/questions/6610348
复制相似问题