如何使用ASIHTTP将图像上传到网络服务器

时间:2012-05-26 08:46:06

标签: iphone

如何使用ASIHTTP从库或相机上传图像?

NSString *post;
self.view.userInteractionEnabled = FALSE;
post = [NSString stringWithFormat:@"    "];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *urlString1 = [NSString stringWithFormat:/* [...] */];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSURL *myWebserverURL = [NSURL URLWithString:urlString1]; 
NSMutableURLRequest *request1 = [[[NSMutableURLRequest alloc] init] autorelease];

[request1 setURL:myWebserverURL];
[request1 setHTTPMethod:@"POST"];
[request1 setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request1 setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request1 setHTTPBody:postData];

connectionFlag = FALSE; 

conn = [[NSURLConnection alloc] initWithRequest:request1 delegate:self];


if (conn){
    receivedData = [[NSMutableData data] retain];

} else {
    isValidation = FALSE;
    NSLog(@"no data retrieved");
}   

这是我为文本字段做的事情

0 个答案:

没有答案