Bug 19917 - HttpClientVsRestSharp Proxy is not working
Summary: HttpClientVsRestSharp Proxy is not working
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: master
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-05-20 06:58 UTC by Mustafa Shaik
Modified: 2014-05-27 03:25 UTC (History)
2 users (show)

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

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:

Description Mustafa Shaik 2014-05-20 06:58:03 UTC
I was using RestSharp as an HttpClient in my code. But because of the requirement of moving my code to PCL, I had to move to HttpClient. Everything works fine but lately realized that the default behavior that used to work with RestSharp is not working with HttpClient.

***Problem: By setting the WiFi proxy from my iPhone (http://www.ibvpn.com/billing/knowledgebase/72/How-to-configure-proxy-usage-for-iphoneipad.html) and if I launch my app that makes an Http call, I could able to see the requests happening in Charles client. This is happening well with RestSharp but fails with HttpClient.

Please find the attached sample that has 2 projects, NonPCL.core and CCube.Core projects that generates NonPCL .dll using RestSharp to make an Http call and PCL .dll using HttpClient to make an Http call. Both attempts to fetch the contents of bing.com and displays in the textview.

***How to integrate PCL(HttpClient)/NonPCL(RestSharp) version.
1. Provide manual proxy in iPhone over wifi. (http://www.ibvpn.com/billing/knowledgebase/72/How-to-configure-proxy-usage-for-iphoneipad.html).
2. Relaunch/Launch charles.app.
3. From the sample, CoreTest, provide the reference for CCube.Core (PCL).dll to use HttpClient to make http call.
4. Execute the iPhone project.
5. Charles will ask for permission to Allow the phone to access and Allow to show logs.

Follow the same for NonPCL.core project for Step 3.

***Observation: NonPCL(RestSharp) versioned Http Request will be logged inside Charles.app whereas PCL(HttpClient) fails.

Am I missing anything here. Kindly help me on the same.
Comment 1 Mustafa Shaik 2014-05-20 07:14:03 UTC
Sample Url: http://tinyurl.com/HttpClientVsRestSharp-Proxy
Comment 2 Rolf Bjarne Kvinge [MSFT] 2014-05-20 07:16:01 UTC
You have to configure the proxy for HttpClient manually, it will not pick up the system proxy by default.

See here: http://stackoverflow.com/a/23678569/183422
Comment 3 Mustafa Shaik 2014-05-27 01:29:28 UTC
Hi Rolf,
That works fine. But here is the catch.

I want to use native HttpClient like NSUrlSessionHandler() for iOS and OkHttpNetworkHandler for Android rather than generic HttpClientHandler. And unfortunately neither of the native HttpClients has Proxy field to set the proxy as I did for HttpClientHandler.

Is it a bug that Neither of the Native HttpClients has Proxy field and not even HttpMessageHandler which is the base class for both Native HttpClient (NSUrlSessionHandler, OkHttpNetworkHandler) and HttpClientHandler.

Is there any other way that I can set the Proxy in this case?

Comment 4 Rolf Bjarne Kvinge [MSFT] 2014-05-27 02:24:48 UTC
Are you referring to NSUrlSessionHandler/OkHttpNetworkHandler as shipped by the ModernHttpClient component (https://components.xamarin.com/view/modernhttpclient)?
Comment 5 Mustafa Shaik 2014-05-27 03:14:20 UTC
True Rolf.
Comment 6 Rolf Bjarne Kvinge [MSFT] 2014-05-27 03:25:32 UTC
Then you must contact the provider of the ModernHttpClient component, there's a website link here you can try: https://components.xamarin.com/view/modernhttpclient