1

如何使用 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");
}   

这就是我为文本字段所做的

4

0 回答 0