开发者

Proxies with NSURLRequest

开发者 https://www.devze.com 2023-03-25 09:48 出处:网络
I\'m using NSURLConnection and NSURLRequest to make a connection to a server for my OS X app. Now I would like to implement a specific proxy server connection but I cannot find something about it in

I'm using NSURLConnection and NSURLRequest to make a connection to a server for my OS X app.

Now I would like to implement a specific proxy server connection but I cannot find something about it in the docs.

I want the web view to go straight through a proxy I define, not change the machine/device proxy settings.

Has anyone tried this or know how t开发者_StackOverflow中文版o handle proxies from within Objective-C?


Found the answer myself. I discovered that ASIHTTPRequest has the thing i need:

NSURL *url = [NSURL URLWithString:@"http://minip.no"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setProxyHost:[chosenprox objectForKey:@"host"]];
[request setProxyPort:[[chosenprox objectForKey:@"port"] intValue]];
[request setDelegate:self];
[request startSynchronous];
if ([request error]) {
    [mainFrame loadHTMLString:[[request error] localizedDescription] baseURL:nil];
} else if ([request responseString]) {
    [mainFrame loadHTMLString:[request responseString] baseURL:nil];
}

And it has other nice uses as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消