I have an AWS EC2 instance and an app that I created. The app is for people who get migraines (tracks info, tells them what their trigger(s) are). Now I want to be able to send user input from my application to a server so that I can see trends. I am having difficulty connecting to the server and finding out how I would be able to write files to the server.
I have written this method:
- (void) sendDataToServer:(NSString *)url :(NSString *)key : (NSString *) content{
// define your form fields here:
//NSString *content = @"field1=42&field2=Hello";
NSString *address = [NSString stringWithFormat:@"ssh -i %@ %@", key, url];
NSLog(@"%@", address);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:address]];
[request setHTTPMethod:@"POST"];
NSData *contentData = [content dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:contentData];
NSString *postLength = [NSString stringWithFormat:@"%d",[contentData length]];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
// generates an autoreleased NSURLConnection
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn){
NSLog(@"connection");
}
//[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
//[self doSomethingWithData:data];
if (error){
NSLog(@"ERROR");
}
}];
}
I put the private key from my key pair into the app. How would I use that to connect? Should I not be using my private key? Should I be doing this differently?