iPhone https 发布请求
嗬!我正在尝试使用iPhone登录https服务器。我尝试了不同的解决方案,还有asihttprequest,该解决方案在http普通网站上运行良好,但使用https时,返回数据与登录页面相同。 。 我听说要为 https 做一些不同的事情? 预先感谢
这是我尝试过的代码: 一种带有 asihttprequest
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"https://members.website.com/login.jsp"]] autorelease];
[request setRequestMethod:@"POST"];
[request setPostValue:@"myUser" forKey:@"username"];
[request setPostValue:@"myPass" forKey:@"password"];
[request setPostValue:@"-600" forKey:@"utcoffset"];
[request setPostValue:@"" forKey:@"todaysdate"];
[request setValidatesSecureCertificate:NO];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
NSString *response = [request responseString];
//txResult .text = response;
[txResult loadHTMLString:response baseURL:[NSURL URLWithString:@"https://members.website.com/login.jsp"]];
}
,另一种带有 NSMutableURLRequest
NSString *urlString = [NSString stringWithFormat:@"https://members.website.com/login.jsp"];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
[request setValue:@"myUser" forHTTPHeaderField:@"username"];
[request setValue:@"myPass" forHTTPHeaderField:@"password"];
[request setValue:@"-600" forHTTPHeaderField:@"utcoffset"];
[request setValue:@"" forHTTPHeaderField:@"todaysdate"];
NSHTTPURLResponse* urlResponse = nil;
NSError *error = [[NSError alloc] init];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"Response Code: %d", [urlResponse statusCode]);
if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) {
NSLog(@"Response: %@", result);
//here you get the response
[txResult loadHTMLString:result baseURL:[NSURL URLWithSt
环:@"https://members.website.com/login。 jsp"]]; }
Ho all! I'm trying to' make a login with the iPhone into a https server.. I tried different solution, also asihttprequest and the solution works fine with http normal website, but with https the return data is the same of the login page...
I news to' make something different for https?
Thanks in advance
this is the code that I tried:
one with asihttprequest
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"https://members.website.com/login.jsp"]] autorelease];
[request setRequestMethod:@"POST"];
[request setPostValue:@"myUser" forKey:@"username"];
[request setPostValue:@"myPass" forKey:@"password"];
[request setPostValue:@"-600" forKey:@"utcoffset"];
[request setPostValue:@"" forKey:@"todaysdate"];
[request setValidatesSecureCertificate:NO];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
NSString *response = [request responseString];
//txResult .text = response;
[txResult loadHTMLString:response baseURL:[NSURL URLWithString:@"https://members.website.com/login.jsp"]];
}
and one with the NSMutableURLRequest
NSString *urlString = [NSString stringWithFormat:@"https://members.website.com/login.jsp"];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
[request setValue:@"myUser" forHTTPHeaderField:@"username"];
[request setValue:@"myPass" forHTTPHeaderField:@"password"];
[request setValue:@"-600" forHTTPHeaderField:@"utcoffset"];
[request setValue:@"" forHTTPHeaderField:@"todaysdate"];
NSHTTPURLResponse* urlResponse = nil;
NSError *error = [[NSError alloc] init];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"Response Code: %d", [urlResponse statusCode]);
if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) {
NSLog(@"Response: %@", result);
//here you get the response
[txResult loadHTMLString:result baseURL:[NSURL URLWithSt
ring:@"https://members.website.com/login.jsp"]];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论