Bug 19135 - CFNetworkHandler does not use iOS proxy settings
Summary: CFNetworkHandler does not use iOS proxy settings
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 7.2.1
Hardware: PC Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
: 20271 ()
Depends on:
Blocks:
 
Reported: 2014-04-17 14:42 UTC by John Miller [MSFT]
Modified: 2016-05-24 21:32 UTC (History)
9 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Repro Project (5.39 MB, application/zip)
2014-04-17 14:42 UTC, John Miller [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description John Miller [MSFT] 2014-04-17 14:42:41 UTC
Created attachment 6604 [details]
Repro Project

Using HttpClient with CFNetworkHandler as described here: http://tirania.org/monomac//archive/2013/Jun.html
Does not use the proxy settings on the device as indicated in the post above: "Will automatically track proxy and network settings done to iOS."

# Steps to reproduce
* Setup Charles to work with your iOS device (http://blog.cloudfour.com/using-charles-proxy-to-examine-ios-apps/)
* You can verify the above works first by using Safari to browse www.google.com, Charles will show the data. 
* Run the attached sample on the phone.
* Press the "Ping" button to run the following code:

var httpClient = new HttpClient(new CFNetworkHandler());
var response = await httpClient.GetAsync("http://www.google.com");
var content = await response.Content.ReadAsStringAsync ();
this.webView.LoadHtmlString (content, null);

# Results
* No data is seen by Charles
* Suspecting that CFNetworkHandler is not using the proxy settings

# Expected Results
* See data in Charles for www.google.com

# Workaround
* Adding the ModernHttpClient component and using AFNetworkHandler does produce data in Charles with the same app
using ModernHttpClient;
...

var httpClient = new HttpClient(new AFNetworkHandler());
var response = await httpClient.GetAsync("http://www.google.com");
var content = await response.Content.ReadAsStringAsync ();
this.webView.LoadHtmlString (content, null);

# Notes
* Tested with Xam.iOS 7.2.0.2 and 7.2.1.41 (same results)
Comment 1 Marek Safar 2014-04-22 05:09:01 UTC
Implemented in master
Comment 2 narayanp 2014-06-03 07:38:43 UTC
I have checked this issue with following builds. I am still not seeing data in Charles Proxy after clicking on Ping.

=== Xamarin Studio ===

Version 5.1 (build 322)
Installation UUID: 561c7a69-0a91-4bae-ad7c-f0c79d594337
Runtime:
	Mono 3.4.0 ((no/c3fc3ba)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 304000204

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Xamarin.iOS ===

Version: 7.2.99.1 (Business Edition)
Hash: a82e30c
Branch: 
Build date: 2014-06-02 11:31:47-0400

=== Xamarin.Android ===

Version: 4.14.0 (Trial Edition)
Android SDK: /Users/tajinder/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Build Information ===

Release ID: 501000322
Git revision: e79f17166d197fa4e7b2750c623d3eed3209aa98
Build date: 2014-06-02 18:20:30-04
Xamarin addins: b68a34ef2fc4c46b045dc38e26fb199bfe1b201d

=== Operating System ===

Mac OS X 10.8.4
Darwin Tajinders-iMac.local 12.4.2 Darwin Kernel Version 12.4.2
    Mon Jun 17 18:00:12 PDT 2013
    root:xnu-2050.45.8~1/RELEASE_X86_64 x86_64
Comment 3 Mohit Kheterpal 2014-06-06 09:50:06 UTC
I have checked this issue and I am still getting this issue i.e. no data is displaying in charles proxy when I click on ping button.

Environment info:
=== Xamarin Studio ===

Version 5.1 (build 401)
Installation UUID: 449f40dd-b3f1-4028-9a6b-cca0d1a2307d
Runtime:
	Mono 3.6.0 ((no/8dcee6c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 306000000

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.iOS ===

Version: 7.2.99.420 (Enterprise Edition)
Hash: f293050
Branch: 
Build date: 2014-06-05 09:22:30-0400

=== Xamarin.Android ===

Version: 4.12.4 (Enterprise Edition)
Android SDK: /Users/360logicaxamarinmacmini/Desktop/android-sdk-macosx_Róbert_à
	Supported Android versions:
		1.6   (API level 4)
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Xamarin.Mac ===

Version:

=== Build Information ===

Release ID: 501000401
Git revision: 1e7b4d99e3fa64bb7e1504ef64c94a361d843899
Build date: 2014-06-06 06:13:54-04
Xamarin addins: 2c39ca1ce8e771ebfd5bfb8cf699d1f2cfd9a4ac

=== Operating System ===

Mac OS X 10.8.4
Darwin 360Logicas-Mac-mini.local 12.4.0 Darwin Kernel Version 12.4.0
    Sun Mar 10 18:01:10 PDT 2013
    root:xnu-2050.24.6~1/RELEASE_X86_64 x86_64
Comment 4 Mohit Kheterpal 2014-06-06 09:55:37 UTC
*** Bug 20271 has been marked as a duplicate of this bug. ***
Comment 5 Marek Safar 2014-06-06 10:22:53 UTC
You need to use master and set handler property UseSystemProxy to true
Comment 6 Mohit Kheterpal 2014-06-06 11:04:06 UTC
I have again check this issue after following instruction mention in comment 5 and now I am able see data when I click on ping button as shown in screencast :
http://www.screencast.com/t/W4Blszeq

Hence closing this issue.
Comment 8 Marek Safar 2014-06-26 09:57:36 UTC
You need Xamarin.iOS
Version: 7.2.6 or better
Comment 9 Anuj Bhatia 2014-09-15 20:34:08 UTC
Verified regression on:

Xamarin.iOS
Version: 7.4.0.108 (Enterprise Edition)
Hash: 77efa3f
Branch: 
Build date: 2014-08-26 07:59:55-0400
Comment 10 Brendan Zagaeski (Xamarin Team, assistant) 2014-09-15 21:52:16 UTC
The test case works OK for me on Xamarin.iOS 7.4.0.108 + XamarinVS 3.5.58 (Business Edition).

I tested in Xamarin Studio on Mac and in Visual Studio on Windows.

I suspect the missing piece of the puzzle for comment 9 was the `UseSystemProxy` property from comment 5:
> var httpClient = new HttpClient(new CFNetworkHandler() { UseSystemProxy = true });
Comment 11 Marek Safar 2014-09-16 07:05:36 UTC
Anuj, is it still issue or just misconfiguration ?
Comment 13 Marek Safar 2014-09-16 16:59:42 UTC
Anuj,

Fix1: This should work and if I read the case correctly it works for a customer but only in simulator (mac hw) but fails on a device. There can be many reasons for that, including misconfigured proxy setting on the physical device. More details are needed to see what is wrong here.

Fix2: Wrong, http client is setup without any proxy setting

Fix3: That's classic .net http client handler and it should work but it's not using more optimal native network handler.
Comment 14 Sebastien Pouliot 2016-05-24 21:32:46 UTC
I do not see any pending missing information with the last comment. Closing.