我正在尝试通过网站验证用户名和密码...
我像这样使用 ASIHttpRequest:
- (IBAction)fetchTopSecretInformation:(id)sender{
Ustr = User.text; //Ustr and Pstr are strings
Pstr = Pass.text;
NSURL *url1 = [NSURL URLWithString:[NSString stringWithFormat:@"https://www.MySite/login/"]];
ASIFormDataRequest *request1 = [ASIFormDataRequest requestWithURL:url1];
[request1 setUseKeychainPersistence:YES];
request1.delegate = self;
request1.shouldPresentCredentialsBeforeChallenge = YES;
[request1 setRequestMethod:@"POST"];
[request1 setPostValue:User.text forKey:@"username"];
[request1 setPostValue:Pass.text forKey:@"passwd"];
[request1 setTimeOutSeconds:30];
NSLog(@"Useer :%@",User.text);
[request1 setDidFailSelector:@selector(topSecretFetchFailed:)];
[request1 setDidFinishSelector:@selector(topSecretFetchComplete:)];
[request1 startAsynchronous];
}
- (IBAction)topSecretFetchFailed:(ASIHTTPRequest *)theRequest{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error sending request to the server" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
- (IBAction)topSecretFetchComplete:(ASIHTTPRequest *)theRequest{
int statusCode = [theRequest responseStatusCode];
NSString *statusMessage = [theRequest responseStatusMessage];
NSString *strResponse = [[theRequest responseString] stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *strFinal = [self flattenHTML:strResponse];
NSLog(@"Response :%@",strFinal);
NSLog(@"StatusCode: %d", statusCode);
NSLog(@"StatusMessage: %@", statusMessage);
}
我在 NSLog 中得到如下响应:
jQuery(function($) { $(".main").addClass("show-bg"); });
JavaScript seems to be disabled in your browser.
You must have JavaScript enabled in your browser to utilize the functionality of this website.
This is a demo store. Any orders placed through this store will not be honored or fulfilled.
+995 91 190601
მოგესალმებით ელექტრონული წიგნების მაღაზიაში
READERwill.com
კალათა
კალათა GEL 0,00
სავაჭრო კალათა ცარიელია.
ჩემი ბიბლიოთეკა
სურვილები
რეგისტრაცია
.
.
.
.
.
状态代码和状态消息是
StatusCode: 200
StatusMessage: HTTP/1.1 200 OK
这个响应是什么以及如何使用它进行身份验证
在我的网络服务中,如果用户名和密码正确,则会显示“成功”消息,否则会显示失败消息...
最佳答案
如果您正在从事新项目,那么您不应该使用 ASIHTTP 框架。检查此链接 http://allseeing-i.com/ASIHTTPRequest/ 中给出的说明最后一次更新是在 2011 年。
尝试在 NSLog 中仅显示“strResponse”。我认为它应该正确显示响应。
关于iphone - ASIHttpRequest登录身份验证问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18074541/