嗨,我是Ios的初学者,在我的项目中,我必须将图像或视频发送到服务器,因为我使用了以下代码,但没有工作,我在这里使用 java是web服务器请帮帮我一个
NSString *strURL = @"enter uerl hear...";
// ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:strURL]];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:strURL]]; // Upload a file on disk
NSString *filename1=[NSString stringWithFormat:@"friendship.jpg"];
UIImage *image1=[UIImage imageNamed:filename1];
NSData *imageData1=UIImageJPEGRepresentation(image1, 1.0);
[request setData:imageData1 withFileName:filename1 andContentType:@"image/jpeg" forKey:@"avatar"];
[request setRequestMethod:@"POST"];
//[request appendPostData:body];
[request setDelegate:self];
[request setTimeOutSeconds:3.0];
request.shouldAttemptPersistentConnection = NO;
[request setDidFinishSelector:@selector(uploadRequestFinished:)];
[request setDidFailSelector:@selector(uploadRequestFailed:)];
[request startAsynchronous];
- (void)uploadRequestFinished:(ASIHTTPRequest *)request
{
NSLog(@" Error - Statistics file upload failed: \"%@\"",[request responseString]);
}
- (void)uploadRequestFailed:(ASIHTTPRequest *)request{
NSLog(@" Error - Statistics file upload failed: \"%@\"",[[request error] localizedDescription]);
}