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];//開始傳輸