gpt4 book ai didi

没有 UIWebView 的 iOS 应用程序身份验证

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:44:57 25 4
gpt4 key购买 nike

有没有办法在 Flask(Python) 后端没有 webview 的情况下对用户进行身份验证?

这是我的后端登录代码:

@app.route('/login/', methods=['POST'])
def login():
params = json.loads(request.data)
username = params['username']
password = params['password']
u = User.query.filter_by(username=username).first()
if u:
if utils.check_password_hash(password, u.pw_hash):
login_user(u)
return ('', 200)
else:
return ('', 400)
else:
return ('', 400)

最佳答案

是的,您绝对可以做到。这是我通常的做法,根据您的需要更改它(请记住,NSJSONSerialization 仅在 iOS 5+ 中可用):

@property (nonatomic) NSOperationQueue *basicQueue; //add this to your header or as an instance variable

-(void)logMeIn:(NSString *)username password:(NSString *)password {

basicQueue = [[NSOperationQueue alloc] init];

NSDictionary *userCredentialsDict = [NSDictionary dictionaryWithObjectsAndKeys:username, @"username", password, @"password", nil];
NSData *encodedDict = [NSJSONSerialization dataWithJSONObject:userCredentialsDict options:NSJSONWritingPrettyPrinted error:NULL];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://yoursite.com/login"]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:encodedDict];
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

[NSURLConnection sendAsynchronousRequest:request queue:basicQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*) response;
NSString *stringFromData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (httpResponse.statusCode == 200) {
//do stuff
NSLog(@"Received data, parsed into string: %@", stringFromData);
} else {
//do error stuff or whatever
}

}];

欲了解更多信息,查看

关于没有 UIWebView 的 iOS 应用程序身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14986980/

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