0

私は、人々がいくつかのデータを入力して私のメールに送信できるアプリを持っています。メールは送信され、メールの本文が空であることを除いて正常に機能しています。

接続のための私の方法:

-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {

    if( !(buttonIndex == [actionSheet cancelButtonIndex]) ) {

        NSString *post  = nil;
        post = [[NSString alloc] initWithFormat:@"Naam spel = %@ Uitleg= %@", spelnaam.text ,Uitleg.text];
        NSLog(@"dit wordt verstuurd %@", post); //works fine!

        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
        NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
        [request setURL:[NSURL URLWithString:@"http://www.myserver.nl/theemailfile.php"]];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:postData];
        [ NSURLConnection connectionWithRequest:request delegate:self ];

        [post release]; 
        [self displayAlert];
    }
}

私のphpファイル:

<?php
 $message = $_REQUEST['message'] ;
 mail( "emailadres@gmail.com", "Test Message", $message );
?>
4

1 に答える 1

2

HTTPリクエストでは、リクエストの本文で送信する情報はタイプであると言っていますが、application/x-www-form-urlencodedそうではありません。ただの自由形式のテキストのようです。HTML仕様で説明されている形式に準拠する必要があります。次のようなメッセージを送信しています。

Naam spel = test Uitleg= test

次のようなものを送信する必要があります。

message=This+is+a+test&other=test
于 2013-03-21T11:23:52.023 に答える