ASIHTTPRequest 框架支持文件的上传;
文件的上传使用ASIFormDataRequest;
NSString *s = @"文件传输"; NSURL *url = [NSURL URLWithString:@"http://localhost:8080/text"];//传输地址 ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingMacChineseSimp);//编码格式 [request setStringEncoding:enc]; [request setPostValue:s forKey:@"title"]; [request setFile:@"Users/...." forKey:@"文件名"]; [request setDelegate:self]; [request setDidFinishSelector:@selector(Finish)];//完成时调用的函数 [request setDidFailSelector:@selector(Fail )];//失败时调用的函数 [request startSynchronous];//开始传输
这样我们就能完成我们的文件传输任务了;
时间: 2024-12-19 14:52:31