- HTTPS request with Cocoa/objective-C
- -(void)Authenticate
- {
- self.responseData = [NSMutableData data];
- NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://10.84.4.2:8444/fish-mobile/GetPIN.jsp?MSISDN=12345"]];
- //NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
- [[NSURLConnection alloc] initWithRequest:request delegate:self];
- }
- - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
- [responseData setLength:0];
- }
- - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
- return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
- }
- - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge {
- [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
- [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
- }
- - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
- [responseData appendData:data];
- }
- - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
- self.responseData = nil;
- }
- - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
- NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
- NSLog(@"%@", responseString);
- }
- [responseData setLength:0];
- [responseData appendData:data];
- -(void) testme: (NSString *) link{
- NSURL * url = [NSURL URLWithString:link];
- NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:url];
- [request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
- [request setHTTPMethod:@"GET"];
- [[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES];
- - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
- return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];