我正在一个项目中,我必须将用户的详细信息发送到服务器以在应用程序中注册。我已经完成了UI的工作,但是找不到如何向用户发送详细信息(例如姓名,电话号码,地址和所有信息)的解决方案。我需要一个人从一开始就指导我完成整个过程。后端已经写好了,它是用PHP编写的。
它起作用100%
NSString *post = [NSString stringWithFormat:@"username=%@&password=%@",@"Raja",@"12345"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[post length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://localhost/promos/index.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
NSURLConnection *theConnection = [NSURLConnection connectionWithRequest:request delegate:self];
if( theConnection ){
// indicator.hidden = NO;
mutableData = [[NSMutableData alloc]init];
}
您的PHP代码
<?php
$username = $_POST['username'];
$password=$_POST['password'];
echo $username;
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句