简体   繁体   中英

How do I connect over a VPN IP Address in iPhone Simulator using AFNetworking?

- (NSString *)baseURL pulls a String from a file.

NSString *endpoint = @"/authentication.json";
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

NSString *token = @"mytokenvalue"

[manager.requestSerializer setValue:token forHTTPHeaderField:TOKEN_HEADER];
manager.requestSerializer = [AFJSONRequestSerializer serializer];

NSString *path = [NSString stringWithFormat:@"%@%@", [self baseURL], endpoint];

[manager    POST:path
    parameters:nil
    success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (operation.response.statusCode == 200) {
            [self.delegate validated:true];
        }
  } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self.delegate validated:false];
}];

(lldb) po error Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn't be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x7bf3ed90 {NSErrorFailingURLKey= https://1.2.3.4/authentication.json , NSErrorFailingURLStringKey= https://1.2.3.4/authentication.json }

I can connect to 1.2.3.4 through VPN in my terminal, but not through AFNetworking. I tried 1.2.3.4 and https://1.2.3.4 .

I have

[AFHTTPRequestOperationManager manager].securityPolicy.allowInvalidCertificates = YES;

In my app Delegate.

How do I connect to this IP through AFNetworking?

EDIT: Great point on validating certificate chain.

I disabled that and validates domain name in AFSecurityPolicy.m

Confirmed that db) po [AFHTTPRequestOperationManager manager].securityPolicy.SSLPinningMode AFSSLPinningModeNone is left on None, too.

So I found the solution. It was the port. cURL was automatically finding the right port, but NSURLconnection wasn't. I had to specify

https://1.2.3.4:12345 as my URL. (my computer's IP)

On my machine I run

socat TCP-LISTEN:12345,fork TCP:5.6.7.8:12345 (where 5.6.7.8 is server IP)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM