gpt4 book ai didi

iphone - 从 UITextField iPhone 获取用户名密码

转载 作者:行者123 更新时间:2023-11-29 04:53:42 25 4
gpt4 key购买 nike

我正在使用下面的代码来连接 HTTP 服务器。这里我将如何修改我的代码,以便通过 UITextField 的输入给出用户名和密码,并且下次连接时将使用保存在 NSUserDefaults 中的相同数据。

NSString *urlAsString = @"http://abc.com/services/user/validate?email=abc@gmail.com&password=123456";

//urlAsString = [urlAsString stringByAppendingString:@"?email=abc@gmail.com"]; 
//urlAsString = [urlAsString stringByAppendingString:@"&pass=123456"];

NSURL *url = [NSURL URLWithString:urlAsString];

NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];

[urlRequest setTimeoutInterval:30.0f];

[urlRequest setHTTPMethod:@"POST"];

NSOperationQueue *queue = [[NSOperationQueue alloc] init];

[NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response,NSData *data, NSError *error) {

if ([data length] >0 && error == nil){

NSString *html = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

NSLog(@"HTML = %@", html);

receivedData = [[NSMutableData data] retain];

}
else if ([data length] == 0 && error == nil){
NSLog(@"Nothing was downloaded.");

}

else if (error != nil){
NSLog(@"Error happened = %@", error);
} }];

最佳答案

 NSString *urlAsString = [NSString stringWithFormat:
@"http://abc.com/services/user/validateemail=%@&password=%@",
myUsernameTextField.text, // abc@gmail.com
myPasswordTextField.text ]; // 1234565

关于iphone - 从 UITextField iPhone 获取用户名密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8391699/

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