我尝试从iPhone应用程序登录此this website,我以为我会使用NSURLSession
之类的东西,因为登录后我只是打算下载HTML
使用NSData *data = [NSData dataWithContentsOfURL:url]
。
如何使用HTML请求传递凭据(用户密码和密码)?
答案 0 :(得分:2)
你拥有那个网站吗??
无论如何试试这个 从浏览器开发者工具中查找登录请求参数这里有3个参数(districtid,Pin,Password)
//创建POST请求,并使用NSURLConnection发送它。
NSURL *url = [NSURL URLWithString:@"https://mistar.oakland.k12.mi.us/novi/StudentPortal/Home/Login"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSString *postString = [NSString stringWithFormat:@"districtid=%@&Pin=%@&Password=%@",....pass values here];
NSData * postBody = [postString dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody: postBody];
[request addValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
// do whatever with the data...and errors
if ([data length] > 0 && error == nil)
else if ([data length] == 0 && error == nil)
else if (error != nil && error.code == ERROR_CODE_TIMEOUT)
else if (error != nil)
}];