gpt4 book ai didi

iphone - 使用 NSMutableURLRequest 进行请求

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

我尝试制作一个登录页面以使用户对网站进行身份验证。我尝试过类似的事情:

    NSURL *myURL = [NSURL URLWithString:@"https://www.freelancer.com/users/onlogin.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:60];
NSLog(@"ispost");
[request setHTTPMethod:@"POST"];
[request setValue:usernameField.text forKey:@"username"];
[request setValue:passwordField.text forKey:@"passwd"];


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

if (!theConnection) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Network Error" message:@"Could not login!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
return;
}

我遇到了如下错误:

2012-07-07 10:09:37.354 Auth[6062:f803] ispost
2012-07-07 10:09:37.357 Auth[6062:f803] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSMutableURLRequest 0x68d69d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key username.'

谁能告诉我我做错了什么?

感谢您的帮助

最佳答案

你为什么不使用like

[request setValue:usernameField.text forHTTPHeaderField:@"username"];
[request setValue:passwordField.text forHTTPHeaderField:@"passwd"];

希望这对您有帮助。

关于iphone - 使用 NSMutableURLRequest 进行请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11371985/

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