[cpp]
?UIImage *im = [UIImage imageWithContentsOfFile:path];//通過path圖片路徑獲取圖片
NSData *data = UIImagePNGRepresentation(im);//獲取圖片數據
/*
ios中獲取圖片的方法有兩種,一種是UIImageJPEGRepresentation ,一種是UIImagePNGRepresentation
前者獲取到圖片的數據量要比後者的小很多。。
*/
NSMutableData *imageData = [NSMutableData dataWithData:data];//ASIFormDataRequest 的setPostBody 方法需求的為NSMutableData類型
NSURL *url = [NSURL URLWithString:@"服務器地址"];
ASIFormDataRequest *aRequest = [[ASIFormDataRequest alloc] initWithURL:url];
[aRequest setDelegate:self];//代理
[aRequest setRequestMethod:@"POST"];
[aRequest setPostBody:imageData];
[aRequest addRequestHeader:@"Content-Type" value:@"binary/octet-stream"];//這裡的value值 需與服務器端 一致
[aRequest startAsynchronous];//開始。異步
[aRequest setDidFinishSelector:@selector(headPortraitSuccess)];//當成功後會自動觸發 headPortraitSuccess 方法
[aRequest setDidFailSelector:@selector(headPortraitFail)];//如果失敗會 自動觸發 headPortraitFail 方法
[aRequest release];