views:

3009

answers:

4

I'm coding an iPhone app that needs to make small HTTP requests to the Internet. Within our corp LAN, all HTTP traffic has to go through Squid.

The simulator is clearly capable of using a proxy - since Mobile Safari works. But, how do I get/set the proxy settings in code?

A bunch of the headers are commented out for the simulator. For example,

CFNetworkCopySystemProxySettings

In CFProxySupport.h is not available to the simulator - only to the device. I've tried hardcoding like this:

CFReadStreamSetProperty(stream, kCFProxyHostNameKey, @"internal.proxy.servername");
CFReadStreamSetProperty(stream, kCFProxyPortNumberKey, [NSNumber numberWithInt:80]);
CFReadStreamSetProperty(stream, kCFProxyTypeKey, kCFProxyTypeHTTP);

But no joy.

Thoughts?

A: 

You can try using Proxifier: http://www.proxifier.com/mac/ It enables you to set a proxy to any program.

Not what you asked but it should solve your problem.

Alexandre L Telles
+2  A: 

You can try:
"System Preferences" -> "Network" -> Select your network device -> "Advanced" -> "Proxies"

weichsel
A: 

The simulator is probably not capable of using a proxy. It is using the standard networking stack provided by Mac OS X, and that is what is using the proxy.

If the constants are commented out during simulator use, and you've tried hard-coding it with no luck, then this is probably one of the many things that is simply not the same between the simulator and a device, and you'll have to test this part of your application on a device.

Steve Madsen
A: 

This question is a bit old, but thought I would add my findings for reference. In the iOS 4.x SDK at least, the following code works on both the simulator and the iPhone.

CFDictionaryRef systemProxyDict = CFNetworkCopySystemProxySettings();
CFReadStreamSetProperty(m_resultRef, kCFStreamPropertyHTTPProxy, systemProxyDict);
Kevin Campbell