19

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?

Michal Sznajder
  • 9,338
  • 4
  • 44
  • 62
Dan Bennett
  • 1,450
  • 1
  • 15
  • 17

8 Answers8

6

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

Thomas Zoechling
  • 34,177
  • 3
  • 81
  • 112
5

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.

Dan Bennett
  • 1,450
  • 1
  • 15
  • 17
5

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
  • 3,375
  • 29
  • 26
  • Could you post the name of the application you used in proxifier? – Júlia Garrigós Mar 29 '18 at 19:21
  • Not really the answer to the original question. But I think a lot of people searching this question, like me, are trying to setup a proxy to capture HTTP traffic for the staging app running on iOS. I've spent a few days working on this, even trying to modify my Mayo/Alamofire, but so far, I think Proxifier is the easiest. – GummyBear21 Jul 12 '20 at 13:22
2

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

Community
  • 1
  • 1
g212gs
  • 863
  • 10
  • 26
2

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.

John
  • 613
  • 1
  • 8
  • 11
John
  • 21
  • 1
1

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

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
  • 13,465
  • 4
  • 49
  • 67
0

Just close and reopen simulator after applying configuration.

Yan
  • 1,569
  • 18
  • 22