0


this is my snippet:

NSString *post = @"from=A&name=B&email=ciccio@aaasd.com&messaggio=MESSAGE&codHidden=-1";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];    

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://www.mysite.com/page.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData]; 

NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSLog(@"Succeeded! Received %d bytes of data",[urlData length]);
NSString *outputdata = [[NSString alloc] initWithData:urlData encoding:NSASCIIStringEncoding];
NSLog(@"%@", outputdata);

It call a php page that send me an email...

Is there any errors in this code?
Does not seem to work...

thanks

elp
  • 8,021
  • 7
  • 61
  • 120

2 Answers2

0

Try to change NSASCIIStringEncoding to NSUTF8StringEncoding

Max
  • 16,679
  • 4
  • 44
  • 57
0

Is it a Synchronous/Asynchronous problem? If so, use the delegate-pattern and access the data asynchronously. Could you post any errors you see (or the server's response string)?

EDIT: Since you're not doing anything useful with the error returned, change your class to do the request asynchronously. A great answer to this was previously posted here. Once you implement didFailWithError you'll have a better picture.

Community
  • 1
  • 1
Alan Zeino
  • 4,406
  • 2
  • 23
  • 30
  • No error, no response (because the page return an empty string), and no mail! The code is correct? If yes, I have to order change/fix the php page... – elp Feb 01 '11 at 22:15
  • Well, firstly, you're not sending your NSError response to an object you can investigate after the method returns. So, change the above to `NSError *returnedError; NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&returnedError];` – Alan Zeino Feb 01 '11 at 22:18