首页 > Three20用TTURLRequest发送图片不成功啊

Three20用TTURLRequest发送图片不成功啊

我写了这么个方法用来发送图片。怎么看也没错啊。打印TTURLRequest的日志出来看,显示数据已经发出去了。

可是服务器返回的提示就说图片文件为空,这是为什么呀?

+ (void)doAsynchronousRequestPost:(NSString *)url 
							 File:(NSDictionary *)file
						 Delegate:(id)delegate 
						 WithInfo:(NSDictionary *)info {

	TTURLRequest *request = [self requestPost:url Delegate:delegate];
	
	request.response = [[[TTURLJSONResponse alloc] init] autorelease];
	
	if (nil != info) {
		[request setUserInfo:info];
	}
	
	if (nil != file) {
		NSData *imageData = UIImageJPEGRepresentation([file objectForKey:@"data"], 0.7f);
		[request addFile:imageData mimeType:[file objectForKey:@"type"] fileName:[file objectForKey:@"key"]];
	} else {
		return;
	}
	
	[request send];

}

还是我自己来回答吧。

TTURLRequest的generatePostBody方法中开头默认添加有一句:

[body appendData:[[NSString stringWithFormat:@"--%@\r\n", kStringBoundary]
    dataUsingEncoding:NSUTF8StringEncoding]];

这样会造成httpbody体中的第一个entity的数据为空。

很多服务器上去的是第一个entity的缘故把。

只要把这句话注释掉就好了。

【热门文章】
【热门文章】