开发者

Why this POST don't work?

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:@"开发者_StackOverflow中文版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


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.


Try to change NSASCIIStringEncoding to NSUTF8StringEncoding

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜