Iphone 如何登录服务器并在objective-c上获取页面源代码?
我试图通过objective-c上的NSURLConnection通过POST方法发送我的用户名和密码来登录服务器,但这是从我的NSLog中得到的 NSLog:Iphone 如何登录服务器并在objective-c上获取页面源代码?,iphone,objective-c,ios,httprequest,Iphone,Objective C,Ios,Httprequest,我试图通过objective-c上的NSURLConnection通过POST方法发送我的用户名和密码来登录服务器,但这是从我的NSLog中得到的 NSLog: NSLog: NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"%@",string); 它写入控制台的内容: 404 Not Found
NSLog:
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@",string);
它写入控制台的内容:
404 Not Found
Not Found
Sorry!The page requested was not found.
我刚刚认识到的是,如果我将POST请求的一部分放入注释中,它会将页面源打印到控制台,但当然我无法将用户名和密码发送到服务器。我只是获取登录页面的源代码,但我想在登录后获取源代码。实际上,我想通过使用此会话重定向到另一个页面
本部分:
NSString *post = [NSString stringWithFormat:@"sid=%@&PIN=%@", @"username", @"password"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
[request setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
[request setTimeoutInterval: 15];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postData];
网站上使用的证书是否自行签名?您是否尝试在webview中发出请求以查看它是否在那里工作?不是在请求中吗
试试这个,也许它会给你一些提示。是的,连接可以工作,但当我发出post请求时,它就不工作了。
NSString *post = [NSString stringWithFormat:@"sid=%@&PIN=%@", @"username", @"password"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
[request setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
[request setTimeoutInterval: 15];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postData];