【发布时间】:2012-12-11 08:24:06
【问题描述】:
我正在尝试向 youtube 发送发布请求,以将视频添加到收藏列表。 API文档是here
这是我的源代码:
- (void) addVideoToFavoriteWithID:(NSString *)strVideoID{
NSString* strConnection = [NSString stringWithFormat:@"%@%@",CONNECTION_YOUTUBE, CONNECTION_ADD_VIDEO_TO_FAVORITE];
AppDelegate* delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
ASIFormDataRequest *formData = [[ASIFormDataRequest alloc]initWithURL:[NSURL URLWithString:strConnection]];
[formData setRequestMethod:@"POST"];
[formData setPostValue:@"2" forKey:@"GData-Version"];
[formData setPostValue:@"application/atom+xml" forKey:@"Content-Type"];
[formData setPostValue:YOUTUBE_DEVELOPER_KEY forKey:@"X-GData-Key"];
[formData setPostValue:[[delegate userInfo ]accessTokenYoutube] forKey:@"Authorization"];
NSString *body = [NSString stringWithFormat:@"<?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom'><id>%@</id></entry>",strVideoID];
[formData setPostValue:body forKey:@"body" ];
[formData setDelegate:self];
[formData setDidFinishSelector:@selector(didAddVideoToFavoriteFinish:)];
[formData setDidFailSelector:@selector(didAddVideoToFavoriteFail:)];\
[formData setDidReceiveDataSelector:@selector(didAddVideoToFavoriteSelect:)];
[formData startAsynchronous];
[formData release];
}
在didAddVideoToFavoriteFinish方法中,收到消息:
HTTP/1.1 415 不支持的媒体类型
请告诉我这里的错误是什么。我是目标 C 的新手,对此我感到非常困惑。
【问题讨论】:
-
[415 Unsupported Media Type] If the client sends a document that’s got the right media type but the wrong format (such as an XML document written in the wrong vocabulary), a better response is the more generic 400 (“Bad Request”)stackoverflow.com/questions/4308672/…
标签: objective-c ios youtube-api asihttprequest