I've been working on a way to send a value to a web-server in objective c.
I think I have everything working on both ends, except for the fact that my value doesn't show up in the email that is sent out.
Here is my code, if someone could point out what I'm doing wrong, that would be great.
(dval is what's not showing up)
NSMutableString *mmessage = [[NSMutableString alloc]initWithString:@""];
[mmessage appendString:[NSString stringWithFormat:@"<p><b>Drink Name:</b> %@</p>", dval]];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://test.com/api/stuff/send"]];
NSMutableDictionary *postInfo = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObjectsAndKeys:mmessage, @"message", nil] forKey:@"form"];
NSError *e = nil;
NSData *postData = [NSJSONSerialization dataWithJSONObject:postInfo options:0 error:&e ];
__block int resp_code = 0;
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:postData];
[NSURLConnection sendAsynchronousRequest:urlRequest
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
resp_code = httpResponse.statusCode;
if(resp_code == 200){
NSDictionary *jsonObjects = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
if ([[jsonObjects objectForKey:@"status"] isEqualToString:@"success"]) {
UIAlertView *emailsuccess = [[UIAlertView alloc] initWithTitle:@"Email Successfully sent." message:nil delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[emailsuccess show];
}
else if ([[jsonObjects objectForKey:@"status"] isEqualToString:@"failed"]) {
UIAlertView *emailfailed = [[UIAlertView alloc] initWithTitle:@"Email Failed." message:[jsonObjects objectForKey:@"messages"] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[emailfailed show];
}
else {
UIAlertView *emailfailed = [[UIAlertView alloc] initWithTitle:@"Email Response." message:[jsonObjects objectForKey:@"messages"] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[emailfailed show];
}
}
}];