Iphone 将Objective-C与ActiveCollab 3 Beta API集成的问题

Iphone 将Objective-C与ActiveCollab 3 Beta API集成的问题,iphone,objective-c,activecollab,Iphone,Objective C,Activecollab,我正在尝试实现一个Objective C程序来与activeCollab 3 beta接口,但遇到了一些问题。我可以在浏览器中输入NSLog输出的url,它可以很好地为所有项目提取xml,当我试图通过这个程序访问它时,它不想为我工作,它给了我一个HTTP 403错误。我不熟悉Objective C,我这样做是为了学习,所以有些代码可能是多余的。提前感谢您的帮助。导入被尖括号包围,但会导致它隐藏在StackOverflow上,因此我将其置于引号中 #import "Foundation/Found

我正在尝试实现一个Objective C程序来与activeCollab 3 beta接口,但遇到了一些问题。我可以在浏览器中输入NSLog输出的url,它可以很好地为所有项目提取xml,当我试图通过这个程序访问它时,它不想为我工作,它给了我一个HTTP 403错误。我不熟悉Objective C,我这样做是为了学习,所以有些代码可能是多余的。提前感谢您的帮助。导入被尖括号包围,但会导致它隐藏在StackOverflow上,因此我将其置于引号中

#import "Foundation/Foundation.h" int main (int argc, const char * argv[]) { NSString *token = @"my-token"; NSString *path_info = @"projects"; NSString *url = @"http://my-site/api.php?"; NSString *post = [[NSString alloc] initWithFormat:@"path_info=%@&auth_api_token=%@",path_info, token]; NSLog(@"Post: %@", post); NSString *newRequest; newRequest = [url stringByAppendingString:post]; NSLog(@"Path: %@", newRequest); NSData *postData = [newRequest dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; [request setURL:[NSURL URLWithString:newRequest]]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:postData]; NSURLResponse *response; NSError *err; NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err]; NSString *returnData = [[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding] autorelease]; NSLog(@"%@", returnData); //printf("Print line"); return 0; } #导入“Foundation/Foundation.h” int main(int argc,const char*argv[]{ NSString*令牌=@“我的令牌”; NSString*路径信息=@“项目”; NSString*url=@”http://my-site/api.php?"; NSString*post=[[NSString alloc]initWithFormat:@“路径信息=%@&身份验证api令牌=%@”,路径信息,令牌]; NSLog(@“Post:%@”,Post); NSString*newRequest; newRequest=[url stringByAppendingString:post]; NSLog(@“路径:%@”,newRequest); NSData*postData=[newRequest dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSMutableURLRequest*请求=[[[NSMutableURLRequest alloc]init]autorelease]; NSString*postLength=[NSString stringWithFormat:@“%d”,[postData长度]]; [请求设置URL:[NSURL URLWithString:NEWLEST]]; [请求设置HttpMethod:@“POST”]; [请求设置值:HttpHeaderField的postLength:@“内容长度”]; [请求设置值:@“应用程序/x-www-form-urlencoded”forHTTPHeaderField:@“内容类型”]; [请求setHTTPBody:postData]; NSURLResponse*响应; n错误*错误; NSData*responseData=[NSURLConnection sendSynchronousRequest:request ReturnInResponse:&响应错误:&错误]; NSString*returnData=[[NSString alloc]initWithData:responseData编码:NSUTF8StringEncoding]autorelease]; NSLog(@“%@”,返回数据); //printf(“打印行”); 返回0; }
您的请求头是限制性的,不必要的,对于AC API,您需要GET请求而不是POST请求

int main (int argc, const char * argv[]) 
{

    NSString *requestString = [[NSString alloc] initWithFormat:@"path_info=%@&auth_api_token=%@", path_info, token];
    NSLog(@"Post: %@", requestString);

    NSString *newRequest;
    newRequest = [url stringByAppendingString: requestString];

    NSLog(@"Path: %@", newRequest);

    NSData *postData = [newRequest dataUsingEncoding: NSASCIIStringEncoding allowLossyConversion: YES];

    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];

    NSLog(@"Data: %@", postData);

    [request setURL: [NSURL URLWithString:newRequest]];
    [request setHTTPMethod: @"GET"];

    NSURLResponse *response;

    NSError *err;
    NSData *responseData = [NSURLConnection sendSynchronousRequest: request returningResponse: &response error: &err];
    NSString *returnData = [[[NSString alloc] initWithData: responseData encoding: NSUTF8StringEncoding] autorelease];
    NSLog(@"Return: %@", returnData);

    //printf("Print line");
    return 0;
}

这是有道理的,我没有注意到我试图发送多个标题,以为它们都是同时发送的。