2014-07-13 18 views
6

Ho un'applicazione IOS che mi piacerebbe inviare una e-mail tramite Mandrill. Ho provato a implementarlo, ma non funziona e Ive si è confuso.IOS JSON invia una e-mail da Mandrill

quando si preme il pulsante per inviare una e-mail dall'applicazione IOS accedo questo messaggio di errore:

{"status":"error","code":-1,"name":"ValidationError","message":"You must specify a key value"} 

Il mio codice è:

NSString *post = [NSString stringWithFormat:@"{\"key\": \"abcdefg123456\", \"raw_message\": \"From: [email protected]\nTo: [email protected]\nSubject: Some Subject\n\nSome content.}"]; 
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; 

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; 
[request setURL:[NSURL URLWithString:@"https://mandrillapp.com/api/1.0/messages/send-raw.json"]]; 
[request setHTTPMethod:@"POST"]; 
[request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; 
[request setHTTPBody:postData]; 
    NSLog(@"Post: %@", post); 

NSURLResponse *response; 
NSData *POSTReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil]; 
NSString *theReply = [[NSString alloc] initWithBytes:[POSTReply bytes] length:[POSTReply length] encoding: NSASCIIStringEncoding]; 
NSLog(@"Reply: %@", theReply); 

Per favore fatemi sapere dove sto andando male. .

risposta

5

Sembra hai dimenticato il \" dopo "contenuto".

provare a scrivere il vostro "post" variabile come segue:.

NSString *post = [NSString stringWithFormat:@"{\"key\": \"abcdefg123456\", \"raw_message\": \"From: [email protected]\nTo: [email protected]\nSubject: Some Subject\n\nSome content.\"}"]; 

Spero che aiuta

+0

Grazie che ho fatto perdere il \ dopo il contenuto. Inoltre mi è stato richiesto di aggiungere un \ prima di ogni \ n – Steve