【发布时间】:2011-02-02 06:22:34
【问题描述】:
这是我的 sn-p:
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);
它调用一个向我发送电子邮件的 php 页面......
这段代码有错误吗?
好像不行……
谢谢
【问题讨论】:
-
我们还需要 PHP 脚本的内容。那里可能有问题。
-
好的。 objc 代码对你有用吗?
-
NSLog()函数记录了什么? -
什么都没有。页面没有返回值...
标签: iphone objective-c nsurlconnection http-post nsmutableurlrequest