将数据上传至服务器的方法(post方法)
来源:互联网 发布:linux时间校准 编辑:程序博客网 时间:2024/06/14 20:24
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)choosePicture:(id)sender
{
UIActionSheet *actionSheet = [[UIActionSheetalloc]initWithTitle:@"选择照片来源"delegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:nilotherButtonTitles:@"从相册中选择",@"从相机拍照",nil];
[actionSheetshowInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIImagePickerController *imagePicker = [[UIImagePickerControlleralloc]init];
imagePicker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.allowsEditing =YES;
imagePicker.delegate =self;
[selfpresentViewController:imagePicker animated:YEScompletion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSLog(@"选中了某张图片 %@",info);
UIImage *image = [infoobjectForKey:UIImagePickerControllerEditedImage];
_imageView.image = image;
[picker dismissViewControllerAnimated:YEScompletion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
NSLog(@"点击了取消");
[picker dismissViewControllerAnimated:YEScompletion:nil];
}
- (IBAction)upload:(id)sender
{
//上传数据一定要用post请求
NSString *urlString =@"http://127.0.0.1:8080/UploadServer/NewServlet";
NSMutableURLRequest *request = [NSMutableURLRequestrequestWithURL:[NSURLURLWithString:urlString]];
//把UIImage转化成NSData
NSData *data =UIImageJPEGRepresentation(_imageView.image,1);
// NSString *path = [[NSBundle mainBundle] pathForResource:@"a" ofType:@"jpg"];
// NSData *data = [[NSData alloc]initWithContentsOfFile:path];
[requestsetHTTPMethod:@"post"];
//小文件上传
[requestsetHTTPBody:data];
//大文件上传用输入流
// NSInputStream *stream = [[NSInputStream alloc]initWithFileAtPath:[[NSBundle mainBundle] pathForResource:@"" ofType:@""]];
// [request setHTTPBodyStream:stream];
[NSURLConnectionconnectionWithRequest:request delegate:nil];
}
@end
- 将数据上传至服务器的方法(post方法)
- 将文件通过http的post方法上传到服务器
- android中用GET和POST的方法向服务器上传数据
- android中用GET和POST的方法向服务器上传数据
- Android使用post方式上传图片到服务器的方法
- Android使用post方式上传图片到服务器的方法
- 将文件上传到网络共享服务器的方法
- 将文件上传到网络共享服务器的方法
- 使用post()方法以POST方式从服务器发送数据
- 从服务器将ORACLE数据导入到本地的方法
- QT 通过POST方法,上传文件到服务器
- Retrofit的POST方法上传头像
- 用Idhttp.post方法将客户端的文本提交给服务器的范例
- 数据下载方法(post方法)
- 用idhttp post 方法发送数据到服务器上。实现数据和网页的交互。
- POST方法向服务器传XML格式数据,并解析获取的数据。
- 简易服务器搭建(get post方法)
- fileinput组件将文件上传到服务器的路径编写方法以及Tomcat的配置
- ContentResolver读取系统联系人数据
- 一天一算法之归并排序
- 经济学模型1-循环流向图
- iOS 应用架构谈 动态部署方案
- win7 批处理获取本地网关
- 将数据上传至服务器的方法(post方法)
- smarty显示二维数组的数据
- const和static const还有static区别
- 数控分频器的设计
- android 限制输入字符数!看清楚:是限制字符数,不是字数!中英混排?就算emoji也不怕啦!
- My_Graph2 DFS BFS
- 第八周--项目5计数的模式匹配
- Lasso
- Docker在windows下无法开启伪终端解决方法