我正在尝试通过我的iPhone App使用Google API上传文档。这是我正在使用的代码:

NSString *authorizationHeader = [NSString stringWithFormat:@"GoogleLogin auth=\"%@\"" ,[another  objectAtIndex:1]];
NSURL *url2 = [NSURL URLWithString:@"docs.google.com/feeds/documents/private/full"];
NSMutableURLRequest *urlRequest2 = [[NSMutableURLRequest alloc]initWithURL:url2];
[urlRequest2 setHTTPMethod:@"POST"];
[urlRequest2 setValue:@"2.0" forHTTPHeaderField:@"GData-Version"];
[urlRequest2 setValue:authorizationHeader forHTTPHeaderField:@"Authorization"];
[urlRequest2 setValue:Length forHTTPHeaderField:@"Content-Length"];
[urlRequest2 setValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
[urlRequest2 setValue:slugStr forHTTPHeaderField:@"Slug"];
[urlRequest2 setHTTPBody:audioData];


其中authorizationHeader包含我的GoogleLogin auth = theToken

通过运行此代码,我从服务器获得以下响应

<HTML>
<HEAD> <TITLE>Token invalid</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Token invalid</H1>
<H2>Error 401</H2>
</BODY>
</HTML>


我不知道我在哪里犯错。标头中是否有错误,或者我传递了错误的参数?

最佳答案

创建NSURL时,网址中的网址是否不应以http://开头?

NSURL *url2 = [NSURL URLWithString:@"http://docs.google.com/feeds/documents/private/full"];

10-01 16:26