2

我想在我的应用程序中连接到 socks 服务器以通过政府过滤。

我正在使用这个组件:Chilkat Socket/SSL/TLS 组件/库

一切正常,我可以连接到服务器。但是 NSURLRequest 不使用代理。

这是我的代码:

NSMutableString *strOutput = [NSMutableString stringWithCapacity:1000];
CkoSocket *socket = [[CkoSocket alloc] init];
BOOL success;
success = [socket UnlockComponent: @"Anything for 30-day trial"];
if (success != YES) {
    [strOutput appendString: socket.LastErrorText];
    [strOutput appendString: @"\n"];
    return;
}

socket.SocksHostname = @"my socks server";
socket.SocksPort = [NSNumber numberWithInt:1080];
socket.SocksUsername = @"user";
socket.SocksPassword = @"pass";
socket.SocksVersion = [NSNumber numberWithInt:5];

success = [socket AsyncConnectStart:@"my socks server" port: [NSNumber numberWithInt: 1080] ssl:NO maxWaitMs: [NSNumber numberWithInt: 20000]];

if (success) {
    NSLog(@"connected");

    NSURLRequest *request = [NSURLRequest requestWithURL:
                             [NSURL URLWithString:@"an image link"]];

    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [NSURLConnection sendAsynchronousRequest:request queue:queue  completionHandler:^(NSURLResponse *response,
                                                                                      NSData *data, NSError *error) {
        if ([data length] >0 && error == nil){
            NSLog(@"%@",data);
            img.image=[[UIImage alloc]initWithData:data];
        }

    }];

} else {
    NSLog(@"not connected");
}

socket.MaxReadIdleMs = [NSNumber numberWithInt:10000];
socket.MaxSendIdleMs = [NSNumber numberWithInt:10000];

连接成功,但数据未通过 socks 服务器。

4

0 回答 0