Dan Bennett
Dan Bennett

Reputation: 1450

iPhone Simulator - set HTTP proxy

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?

Upvotes: 19

Views: 43051

Answers (8)

Yan
Yan

Reputation: 1727

Just close and reopen simulator after applying configuration.

Upvotes: 0

g212gs
g212gs

Reputation: 849

Simply restart the iPhone simulator.

for this i use the following trick

go to setting >> General >> Accessibility >> bold text to switch on >> picker view open and ask for restart for make it effective >> press continue >> iPhone simulator now restart

the pop-up ask for user name and password for proxy...

tested in ios simulator 7.1

Upvotes: 2

John
John

Reputation: 21

Looks like XCode 4.0 (4A304a) has broke this again. If I set the stack to proxy http calls through Burp, works fine with every app (Safari, etc) but the simulator.

Upvotes: 2

Dan Bennett
Dan Bennett

Reputation: 1450

To close this off. It looks like this is fixed in iOS4 SDK - the network stack on the simulator will use the Mac's proxy for any HTTP calls.

Upvotes: 5

Kevin Campbell
Kevin Campbell

Reputation: 19

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);

Upvotes: 1

Steve Madsen
Steve Madsen

Reputation: 13791

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.

Upvotes: 0

Thomas Zoechling
Thomas Zoechling

Reputation: 34253

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

Upvotes: 6

Alexandre L Telles
Alexandre L Telles

Reputation: 3435

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.

Upvotes: 5

Related Questions