Tuesday, 21 May 2019

How can i send https request with .p12 certificate on objective c or swift

I have a react-native project and I have to create Native module for https request with .p12 certification but I never use objective-c (it's a little complicated) or swift I found a class for https request with certification it is but I didn't use this cause I don't have a .h file and my project folder;

MyBridge.h

#import "React/RCTBridgeModule.h"

@interface MyFirstBridge : NSObject <RCTBridgeModule>

@end

MyBridge.m

#import "MyFirstBridge.h"
#import <React/RCTLog.h>

@implementation MyFirstBridge

RCT_EXPORT_MODULE();

RCT_EXPORT_METHOD(sendGetRequest:(NSString *)urllocation:(NSString *)location)
{
  NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:@"GET"];
[request setURL:[NSURL URLWithString:url]];

NSError *error = nil;
NSHTTPURLResponse *responseCode = nil;

NSData *oResponseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&responseCode error:&error];

 if([responseCode statusCode] != 200){
    NSLog(@"Error getting %@, HTTP status code %i", url, [responseCode statusCode]);
    return nil;
}

  callback(@[[NSNull null], [[NSString alloc] initWithData:oResponseData encoding:NSUTF8StringEncoding]]);
}

@end

It works as basic HTTP get request but when I tried https service I need to pin a certificate for each request. How can I send a HTTPS request for this case?



from How can i send https request with .p12 certificate on objective c or swift

No comments:

Post a Comment