![:P](http://www.iphonehellas.gr/forum/public/style_emoticons/default/tongue.gif)
Ευχαριστω
Δημοσίευση 04/07/2010 - 16:20
Δημοσίευση 07/07/2010 - 00:33
- (void) sendSyncDataSynchronously:(id)sender{ NSLog(@"sending Synchronous request"); NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; NSURL * theURL = [NSURL URLWithString:@"http://www.yourwebsite:yourport/code/upload.php"]; NSMutableURLRequest *postRequest = [[NSMutableURLRequest alloc] initWithURL:theURL]; //adding header information: [postRequest setHTTPMethod:@"POST"]; NSString *stringBoundary = [NSString stringWithString:@"0xKhTmLbOuNdArY"]; NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",stringBoundary]; [postRequest addValue:contentType forHTTPHeaderField: @"Content-Type"]; //setting up the body: NSMutableData *postBody = [NSMutableData data]; [postBody appendData:[[NSString stringWithFormat:@"--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"uploadFile\"; filename=\"%@.plist\"\r\n", _deviceToken] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[NSData dataWithContentsOfFile:syncDataZippedFilePath()]]; [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; [postRequest setHTTPBody:postBody]; NSError *requestError; NSData* myData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:nil error:&requestError]; NSString *checkResponse = [[NSString alloc] initWithData:myData encoding:NSASCIIStringEncoding]; NSLog(@"%@", checkResponse); [checkResponse release]; if ([NSURLConnection canHandleRequest:postRequest]){ NSLog(@"OK with request"); } else { NSLog(@"Cannot handle request"); } if (myData == nil) { // Check for problems if (requestError != nil) { NSString *errorIdentifier = [NSString stringWithFormat:@"(%@)[%d] -> %@",requestError.domain, requestError.code, [requestError description]]; NSLog(@"Upload error:%@", errorIdentifier); } } else { NSLog(@"Data uploaded successfully"); // Data was received.. continue processing [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"LastSuccesfulDateSend"]; [[NSUserDefaults standardUserDefaults] setObject:self._newHashString forKey:@"MD5HashString"]; [[NSUserDefaults standardUserDefaults] synchronize]; NSString *aString = [[NSUserDefaults standardUserDefaults] objectForKey:@"MD5HashString"]; NSLog(@"Hash value stored: %@", aString); } [postRequest release]; [pool drain]; }
[self performSelectorInBackground:@selector(sendSyncDataSynchronously:) withObject:nil];
Δημοσίευση 07/07/2010 - 19:40
Δημοσίευση 06/04/2011 - 01:03
0 μέλη, 1 επισκέπτες, 0 ανώνυμοι χρήστες