iPhone https 发布请求

发布于 2024-09-06 04:49:42 字数 2164 浏览 5 评论 0原文

嗬!我正在尝试使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文