gpt4 book ai didi

iphone - 如何在iPhone应用程序中使用post将用户名和密码发送到服务器

转载 作者:行者123 更新时间:2023-12-03 20:31:12 25 4
gpt4 key购买 nike

我正在制作一个 lo-gin 应用程序,我想将用户名和密码发送到服务器以进行验证如何执行此操作,我已经通过多种方式完成了,但我无法发布。我正在发布用户名和密码,但如果我直接将用户名和密码提供给 php,它就不起作用,那么如何在 iphone 中执行此操作以通过帖子发送

NSString *post = [[NSString alloc] initWithFormat:@"UserName=%@&Password=%@",username,pass];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSURL *url = [NSURL URLWithString:@"http://www.celeritas-solutions.com/emrapp/connect.php?"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:postData];

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

if( theConnection )
{
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"Inside the else condition");
}

[nameInput resignFirstResponder];
[passInput resignFirstResponder];
nameInput.text = nil;
passInput.text = nil;

最佳答案

//编辑你的代码尝试这可能对你有帮助。

 NSString *post = [[NSString alloc] initWithFormat:@"UserName=%@&Password=%@",username,pass];

NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSURL *url = [NSURL URLWithString:@"http://www.celeritas-solutions.com/emrapp/connect.php?"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:postData];

关于iphone - 如何在iPhone应用程序中使用post将用户名和密码发送到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9767739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com