Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
427 views
in Technique[技术] by (71.8m points)

iphone - ASIHTTPRequest - HTTPS

Does ASIHTTPRequest support HTTPS connections? My connection right now works for a HTTP connection and errors if I try a HTTPS Connection. (Goes into requestFailed and gives me a ASIHTTPErrorRequestDomain)

-(void) getData
{

av.hidden = NO;
[av startAnimating];

NSString *urlString = [IP stringByAppendingString:@"Method1"];
NSURL *url = [NSURL URLWithString:urlString];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
NSLog(@"URL = %@",url);
[request setRequestMethod:@"POST"];
[request setPostValue:@"val1" forKey:@"key1"];
[request setPostValue:@"val2" forKey:@"key2"];
[request setDelegate:self];
[request startAsynchronous];    
}

- (void)requestFinished:(ASIHTTPRequest *)request
{
    // Use when fetching text data
    //NSString *responseString = [request responseString];

    // Use when fetching binary data
    NSData *responseData = [request responseData];
    [self parseData:responseData];

    [av stopAnimating];
    av.hidden = YES;
}


- (void)requestFailed:(ASIHTTPRequest *)request
{
    NSError *error = [request error];
    [av stopAnimating];     
    av.hidden = YES;
}

Thanks,
Teja

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Whoops, sorry, figured it out -

[request setValidatesSecureCertificate:NO] works for reference.

Thanks to these guys - http://www.iphonedevsdk.com/forum/iphone-sdk-development/29417-asihttprequest-library-works-https.html

EDIT: Since this is getting some upvotes, I'd just like to add that this might not be the best approach for valid SSL certificates. The one I was using was a self-signed certificate, so this was fine.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...