iOS 上传文件到服务器
来源:互联网 发布:软件项目经理培训视频 编辑:程序博客网 时间:2024/05/16 11:01
-(void)UploadAllRecords:(id)sender{ NSUserDefaults* Defaults = [NSUserDefaults standardUserDefaults]; NSLog(@"Upload All Records..."); NSString *stepMsg = [NSString stringWithFormat: @"{" "\"user\""":" "%@," "\"data\""":" "\"%@," "%@," "%@," "5," "0.6," "13.22," "3" ";\"" "}",[Defaults objectForKey:@"UserName"],[Defaults objectForKey:@"LoStr"],[Defaults objectForKey:@"Nowtime"],[Defaults objectForKey:@"NowData"]]; NSLog(@"stepMsg:%@",stepMsg); ZipArchive* zip = [[ZipArchive alloc] init]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; NSString* l_zipfile = [documentpath stringByAppendingString:@"/test.zip"] ; NSString* file = [documentpath stringByAppendingString:@"/a_m.txt"] ; [stepMsg writeToFile:file atomically:YES encoding:NSUTF8StringEncoding error:nil]; NSLog(@"file:%@",file); BOOL ret = [zip CreateZipFile2:l_zipfile]; ret = [zip addFileToZip:file newname:@"flie.txt"]; if( ![zip CloseZipFile2] ) { l_zipfile = @""; } //http://50.116.37.92:8080/ActiveTravel1.2/GetLastPointidByUserid?userId=ycy NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:@"http://50.116.37.92:8080/ActiveTravel1.2/GetLastPointidByUserid?userId=%@",[Defaults objectForKey:@"UserName"]]]; // 根据上面的URL创建一个请求 NSLog(@"url====%@",url); NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; [req setHTTPMethod:@"POST"]; conn = [[NSURLConnection alloc] initWithRequest:req delegate:self]; if (conn) { if (webData) { webData=nil; } webData = [NSMutableData data]; NSLog(@"webData: %@",webData); } //http://10.0.2.2:8080/ActiveTravel1.2/GetPointsFileServlet NSData *data = [NSData dataWithContentsOfFile:l_zipfile]; NSString * newURL =@"http://50.116.37.92:8080"; NSMutableURLRequest *request = [[AFHTTPClient clientWithBaseURL:[NSURL URLWithString:newURL]] multipartFormRequestWithMethod:@"POST" path:[NSString stringWithFormat:@"/ActiveTravel1.2/GetPointsFileServlet"] parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) { [formData appendPartWithFileData:data name:@"test" fileName:@"test.zip" mimeType:@"txt/zip"]; }]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {float progress = totalBytesWritten / (float)totalBytesExpectedToWrite;NSLog(@"Sent %f ..",progress); }];[operation start]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {NSLog(@" ********RequestDidFinish**********: %@ ",[operation responseString]); UIAlertView *alter = [[UIAlertView alloc]initWithTitle:@"UploadAll" message:@"Success" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alter show]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) {NSLog(@"error: %@", operation.responseString); UIAlertView *alter = [[UIAlertView alloc]initWithTitle:@"UploadAll" message:@"Server is not avaliable!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alter show];}];}
执行这个操作之后 返回错误
error: <html><head><title>Apache Tomcat/7.0.39 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - 1</h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u>1</u></p><p><b>description</b> <u>The server encountered an internal error that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>java.lang.ArrayIndexOutOfBoundsException: 1service.point.PointService.assemblingPoint(PointService.java:53)service.point.PointService.addPoint(PointService.java:28)service.MobileService.executeUploadPoints(MobileService.java:13)servlet.GetPointsFileServlet.doPost(GetPointsFileServlet.java:80)javax.servlet.http.HttpServlet.service(HttpServlet.java:647)javax.servlet.http.HttpServlet.service(HttpServlet.java:728)filter.SessionCheckFilter.doFilter(SessionCheckFilter.java:45)</pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the Apache Tomcat/7.0.39 logs.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.39</h3></body></html>
- iOS 上传文件到服务器
- IOS上传文件到JAVA服务器
- iOS上传文件到服务器(ASIHttpRequest)
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- 上传文件到服务器
- iOS - ASI - ASIFormDataRequest 上传文件到服务器(转载)
- 【iOS开发】AFNetworking上传语音文件(.mp3)到服务器
- iOS 上传图片到服务器
- iOS上传图片到服务器
- GATE服务实现的架构
- PQueue
- 无刷新省市三联动(源码)
- MinHeap
- hadoop Partition使用实例
- iOS 上传文件到服务器
- add new node in hadoop without restarting the cluster
- 360与百度,阿里巴巴对阵腾讯
- eclipse插件MemoryAnalyzer
- 从1-49选6个不同的数,输出5组(二)有错?
- 《傅雷家书》-文摘二-男女之事
- UVaOJ111 - History Grading
- 用Servlet监听器实现对在线人数的统计
- Linux日记:cut grep sort wc&uniq