Proxies with NSURLRequest
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.
精彩评论