我是 iPhone 新手。我想将图像上传到服务器。我有网址
http://lifestander.com:8080/fileupload/uploadfile.html?username=tom&password=1234&directory=ebay&filename=fantacy.jpg
我使用以下方法上传文件,但控制台中的结果是:{"success":"false", "message":"Authentication Failed"}
我不明白控制台中的输出。所以请告诉我我做错了什么,或者改进我的代码。该怎么办?
谢谢。
-(void)uploadFile{
UIImage* theImage = [UIImage imageNamed:@"images.jpg"];
NSString* path = [[NSBundle mainBundle] pathForResource:@"images" ofType:@"jpg"];
NSString *photoUploadURLString=@"http://lifestander.com:8080/fileupload/uploadfile.html";
NSURL *url = [NSURL URLWithString: photoUploadURLString];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setUseKeychainPersistence:YES];
// Upload an image
NSData *imageData = UIImageJPEGRepresentation(theImage,1.0);
[request addPostValue:@"tom" forKey:@"username"];
[request addPostValue:@"1234" forKey:@"password"];
[request addPostValue:@"ebay" forKey:@"directory"];
[request setData:imageData withFileName:@"images.jpg" andContentType:@"image/jpg" forKey:@"filename"];
[request setDelegate:self];
[request setDidFinishSelector:@selector(uploadRequestFinished:)];
[request setDidFailSelector:@selector(uploadRequestFailed:)];
[request startAsynchronous];
}