├── .gitmodules ├── component ├── .gitignore ├── icon_128x128.png ├── icon_512x512.png ├── xamarin-component.exe ├── GettingStarted.md ├── Details.md ├── component.yaml ├── License.md └── Makefile ├── .gitignore ├── vendor └── nuget │ ├── NuGet.exe │ ├── NuGet.Config │ └── NuGet.targets ├── ext ├── monotouch │ └── Newtonsoft.Json.dll └── portable-headers │ └── System.Net.Http.dll ├── samples ├── HttpClient.iOS │ ├── Resources │ │ ├── Default.png │ │ ├── icon-29.png │ │ ├── icon-50.png │ │ ├── icon-57.png │ │ ├── icon-58.png │ │ ├── icon-72.png │ │ ├── icon-100.png │ │ ├── icon-114.png │ │ ├── icon-144.png │ │ ├── Default@2x.png │ │ ├── iTunesArtwork.png │ │ ├── Default-568h@2x.png │ │ ├── iTunesArtwork@2x.png │ │ ├── Default-Landscape~ipad.png │ │ ├── Default-Portrait~ipad.png │ │ ├── Default-Portrait@2x~ipad.png │ │ └── Default-Landscape@2x~ipad.png │ ├── Screenshots │ │ └── HttpClient.jpg │ ├── README.md │ ├── Metadata.xml │ ├── NetHttp.cs │ ├── DotNet.cs │ ├── HttpClient.iOS.sln │ ├── Info.plist │ ├── MainWindow.xib.designer.cs │ ├── TableViewRocks.cs │ ├── Main.cs │ ├── HttpClient.csproj │ └── MainWindow.xib └── HttpClient.Android │ ├── Resources │ ├── drawable │ │ └── Icon.png │ ├── values │ │ └── Strings.xml │ ├── layout │ │ ├── ShowStream.axml │ │ └── Main.axml │ ├── AboutResources.txt │ └── Resource.designer.cs │ ├── packages.config │ ├── Properties │ ├── AndroidManifest.xml │ └── AssemblyInfo.cs │ ├── Assets │ └── AboutAssets.txt │ ├── ShowStream.cs │ ├── NetHttp.cs │ ├── HttpClient.Android.sln │ ├── DotNet.cs │ ├── MainActivity.cs │ └── HttpClient.Android.csproj ├── src ├── Playground.Android │ ├── Resources │ │ ├── drawable │ │ │ └── Icon.png │ │ ├── values │ │ │ └── Strings.xml │ │ ├── layout │ │ │ └── Main.axml │ │ ├── AboutResources.txt │ │ └── Resource.designer.cs │ ├── packages.config │ ├── Properties │ │ ├── AndroidManifest.xml │ │ └── AssemblyInfo.cs │ ├── Assets │ │ └── AboutAssets.txt │ ├── Playground.Android.csproj │ └── MainActivity.cs ├── ModernHttpClient │ ├── Resources │ │ ├── values │ │ │ └── Strings.xml │ │ ├── Resource.designer.cs │ │ └── AboutResources.txt │ ├── packages.config │ ├── CaptiveNetworkException.cs │ ├── iOS │ │ ├── NativeCookieHandler.cs │ │ ├── AsyncLock.cs │ │ ├── NSErrorExtended.cs │ │ └── CFNetworkErrors.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Android │ │ ├── NativeCookieHandler.cs │ │ ├── ConcatenatingStream.cs │ │ └── OkHttpNetworkHandler.cs │ ├── Utility.cs │ ├── ModernHttpClient.Portable.csproj │ ├── ModernHttpClient.iOS64.csproj │ ├── Facades.cs │ ├── ModernHttpClient.iOS.csproj │ ├── ModernHttpClient.Android.csproj │ └── ProgressStreamContent.cs └── Playground.iOS │ ├── Entitlements.plist │ ├── Main.cs │ ├── Info.plist │ ├── Playground_iOSViewController.designer.cs │ ├── AppDelegate.cs │ ├── Playground_iOSViewController.xib │ ├── Playground_iOSViewController.cs │ └── Playground.iOS.csproj ├── COPYING ├── ModernHttpClient.nuspec ├── README.md ├── Makefile ├── CODE_OF_CONDUCT.md └── ModernHttpClient.sln /.gitmodules: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /component/.gitignore: -------------------------------------------------------------------------------- 1 | *.xam 2 | 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | bin/ 3 | obj/ 4 | build/ 5 | *.userprefs 6 | build/ 7 | *.xam 8 | packages 9 | -------------------------------------------------------------------------------- /vendor/nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/vendor/nuget/NuGet.exe -------------------------------------------------------------------------------- /component/icon_128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/component/icon_128x128.png -------------------------------------------------------------------------------- /component/icon_512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/component/icon_512x512.png -------------------------------------------------------------------------------- /component/xamarin-component.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/component/xamarin-component.exe -------------------------------------------------------------------------------- /ext/monotouch/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/ext/monotouch/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /ext/portable-headers/System.Net.Http.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/ext/portable-headers/System.Net.Http.dll -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Resources/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Resources/Default.png -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Resources/icon-29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Resources/icon-29.png -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Resources/icon-50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Resources/icon-50.png -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Resources/icon-57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Resources/icon-57.png -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Resources/icon-58.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Resources/icon-58.png -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Resources/icon-72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Resources/icon-72.png -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Resources/icon-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Resources/icon-100.png -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Resources/icon-114.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Resources/icon-114.png -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Resources/icon-144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Resources/icon-144.png -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Resources/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Resources/Default@2x.png -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Screenshots/HttpClient.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Screenshots/HttpClient.jpg -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Resources/iTunesArtwork.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Resources/iTunesArtwork.png -------------------------------------------------------------------------------- /src/Playground.Android/Resources/drawable/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/src/Playground.Android/Resources/drawable/Icon.png -------------------------------------------------------------------------------- /samples/HttpClient.Android/Resources/drawable/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.Android/Resources/drawable/Icon.png -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Resources/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Resources/Default-568h@2x.png -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Resources/iTunesArtwork@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Resources/iTunesArtwork@2x.png -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Resources/Default-Landscape~ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Resources/Default-Landscape~ipad.png -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Resources/Default-Portrait~ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Resources/Default-Portrait~ipad.png -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Resources/Default-Portrait@2x~ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Resources/Default-Portrait@2x~ipad.png -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Resources/Default-Landscape@2x~ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xamarin/ModernHttpClient/HEAD/samples/HttpClient.iOS/Resources/Default-Landscape@2x~ipad.png -------------------------------------------------------------------------------- /src/ModernHttpClient/Resources/values/Strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | ModernHttpClient.Android 4 | 5 | -------------------------------------------------------------------------------- /vendor/nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Playground.Android/Resources/values/Strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Download some stuff 4 | Playground.Android 5 | -------------------------------------------------------------------------------- /src/Playground.iOS/Entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /samples/HttpClient.iOS/README.md: -------------------------------------------------------------------------------- 1 | HTTP Client 2 | =========== 3 | 4 | An example on using both the .NET and Objective-C classes to 5 | send a web request in one MonoTouch application. 6 | 7 | 8 | Authors 9 | ------- 10 | 11 | Miguel de Icaza 12 | -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Metadata.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | d01773c4-0073-4ca2-852f-2c2781f12484 4 | false 5 | Beginning 6 | Web 7 | 8 | -------------------------------------------------------------------------------- /src/ModernHttpClient/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /samples/HttpClient.Android/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/Playground.Android/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /component/GettingStarted.md: -------------------------------------------------------------------------------- 1 | The good news is, you don't have to know either of these two libraries above, 2 | using ModernHttpClient is the most boring thing in the world. Here's how it 3 | works: 4 | 5 | ```csharp 6 | var httpClient = new HttpClient(new NativeMessageHandler()); 7 | ``` 8 | 9 | ## Other Resources 10 | 11 | * [GitHub page](https://github.com/paulcbetts/ModernHttpClient) 12 | * [OkHttp site](http://square.github.io/okhttp/) 13 | -------------------------------------------------------------------------------- /src/Playground.Android/Properties/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /samples/HttpClient.Android/Properties/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Playground.iOS/Main.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Foundation; 5 | using UIKit; 6 | 7 | namespace Playground.iOS 8 | { 9 | public class Application 10 | { 11 | // This is the main entry point of the application. 12 | static void Main (string[] args) 13 | { 14 | // if you want to use a different Application Delegate class from "AppDelegate" 15 | // you can specify it here. 16 | UIApplication.Main (args, null, "AppDelegate"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /samples/HttpClient.Android/Resources/values/Strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | HTTP Client Sample 4 | Select API: 5 | WebRequest 6 | HttpClient 7 | HttpClient/OkHttp 8 | Issue HTTP Request 9 | The HTML returned by the server: 10 | No data. 11 | Retrieving data... 12 | 13 | -------------------------------------------------------------------------------- /component/Details.md: -------------------------------------------------------------------------------- 1 | This library brings the latest platform-specific networking libraries to Xamarin applications via a custom HttpClient handler. Write your app using System.Net.Http, but drop this library in and it will go drastically faster. This is made possible by two native libraries: 2 | 3 | * On iOS, via NSURLSession 4 | * On Android, via [OkHttp 1.5](http://square.github.io/okhttp/) 5 | 6 | ## Usage 7 | 8 | The good news is, you don't have to know either of these two libraries above, 9 | using ModernHttpClient is the most boring thing in the world. Here's how it 10 | works: 11 | 12 | ```csharp 13 | var httpClient = new HttpClient(new NativeMessageHandler()); 14 | ``` 15 | -------------------------------------------------------------------------------- /samples/HttpClient.iOS/NetHttp.cs: -------------------------------------------------------------------------------- 1 | // 2 | // This file contains the sample code to use System.Net.HttpClient 3 | // on the iPhone to communicate using Apple's CFNetwork API 4 | // 5 | 6 | using System; 7 | using System.Threading.Tasks; 8 | using System.Net.Http; 9 | 10 | namespace HttpClient 11 | { 12 | public class NetHttp 13 | { 14 | AppDelegate ad; 15 | 16 | public NetHttp (AppDelegate ad) 17 | { 18 | this.ad = ad; 19 | } 20 | 21 | public async Task HttpSample (HttpMessageHandler handler) 22 | { 23 | var client = new System.Net.Http.HttpClient (handler); 24 | ad.RenderStream (await client.GetStreamAsync (Application.WisdomUrl)); 25 | } 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/Playground.Android/Assets/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories) and given a Build Action of "AndroidAsset". 3 | 4 | These files will be deployed with your package and will be accessible using Android's 5 | AssetManager, like this: 6 | 7 | public class ReadAsset : Activity 8 | { 9 | protected override void OnCreate (Bundle bundle) 10 | { 11 | base.OnCreate (bundle); 12 | 13 | InputStream input = Assets.Open ("my_asset.txt"); 14 | } 15 | } 16 | 17 | Additionally, some Android functions will automatically load asset files: 18 | 19 | Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); 20 | -------------------------------------------------------------------------------- /samples/HttpClient.Android/Assets/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories) and given a Build Action of "AndroidAsset". 3 | 4 | These files will be deployed with your package and will be accessible using Android's 5 | AssetManager, like this: 6 | 7 | public class ReadAsset : Activity 8 | { 9 | protected override void OnCreate (Bundle bundle) 10 | { 11 | base.OnCreate (bundle); 12 | 13 | InputStream input = Assets.Open ("my_asset.txt"); 14 | } 15 | } 16 | 17 | Additionally, some Android functions will automatically load asset files: 18 | 19 | Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); 20 | -------------------------------------------------------------------------------- /src/Playground.iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDisplayName 6 | Playground.iOS 7 | CFBundleIdentifier 8 | com.your-company.Playground.iOS 9 | UIDeviceFamily 10 | 11 | 1 12 | 13 | UISupportedInterfaceOrientations 14 | 15 | UIInterfaceOrientationPortrait 16 | UIInterfaceOrientationLandscapeLeft 17 | UIInterfaceOrientationLandscapeRight 18 | 19 | MinimumOSVersion 20 | 6.0 21 | 22 | 23 | -------------------------------------------------------------------------------- /samples/HttpClient.Android/ShowStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Android.App; 6 | using Android.Content; 7 | using Android.OS; 8 | using Android.Runtime; 9 | using Android.Views; 10 | using Android.Widget; 11 | 12 | namespace HttpClient.Android 13 | { 14 | [Activity (Label = "Resulting Stream")] 15 | public class ShowStream : Activity 16 | { 17 | protected override void OnCreate (Bundle bundle) 18 | { 19 | base.OnCreate (bundle); 20 | 21 | SetContentView (Resource.Layout.ShowStream); 22 | 23 | var textview = FindViewById (Resource.Id.html_textView); 24 | textview.Text = this.Intent.GetStringExtra ("string") ?? Resources.GetString (Resource.String.no_data); 25 | } 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /samples/HttpClient.Android/NetHttp.cs: -------------------------------------------------------------------------------- 1 | // 2 | // This file contains the sample code to use System.Net.HttpClient 3 | // on the iPhone to communicate using Apple's CFNetwork API 4 | // 5 | 6 | using System; 7 | using System.Threading.Tasks; 8 | using System.Net.Http; 9 | 10 | namespace HttpClient.Android 11 | { 12 | public class NetHttp 13 | { 14 | MainActivity ad; 15 | 16 | public NetHttp (MainActivity ad) 17 | { 18 | this.ad = ad; 19 | } 20 | 21 | public async Task HttpSample (HttpMessageHandler handler = null) 22 | { 23 | this.ad.Busy (); 24 | System.Net.Http.HttpClient client = (handler == null) ? 25 | new System.Net.Http.HttpClient () : 26 | new System.Net.Http.HttpClient (handler); 27 | var stream = await client.GetStreamAsync (MainActivity.WisdomUrl); 28 | this.ad.Done (); 29 | ad.RenderStream (stream); 30 | } 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /samples/HttpClient.Android/HttpClient.Android.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClient.Android", "HttpClient.Android.csproj", "{5A57599D-D355-47EF-B662-DED809E4A1BB}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {5A57599D-D355-47EF-B662-DED809E4A1BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {5A57599D-D355-47EF-B662-DED809E4A1BB}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {5A57599D-D355-47EF-B662-DED809E4A1BB}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {5A57599D-D355-47EF-B662-DED809E4A1BB}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(MonoDevelopProperties) = preSolution 18 | StartupItem = HttpClient.Android.csproj 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /samples/HttpClient.Android/Resources/layout/ShowStream.axml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 13 | 24 | -------------------------------------------------------------------------------- /samples/HttpClient.Android/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using Android.App; 4 | 5 | // Information about this assembly is defined by the following attributes. 6 | // Change them to the values specific to your project. 7 | [assembly: AssemblyTitle ("HttpClient.Android")] 8 | [assembly: AssemblyDescription ("")] 9 | [assembly: AssemblyConfiguration ("")] 10 | [assembly: AssemblyCompany ("")] 11 | [assembly: AssemblyProduct ("")] 12 | [assembly: AssemblyTrademark ("")] 13 | [assembly: AssemblyCulture ("")] 14 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 15 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 16 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 17 | [assembly: AssemblyVersion ("1.0.0")] 18 | // The following attributes are used to specify the signing key for the assembly, 19 | // if desired. See the Mono documentation for more information about signing. 20 | //[assembly: AssemblyDelaySign(false)] 21 | //[assembly: AssemblyKeyFile("")] 22 | 23 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Paul Betts 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /src/Playground.Android/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using Android.App; 4 | 5 | // Information about this assembly is defined by the following attributes. 6 | // Change them to the values specific to your project. 7 | [assembly: AssemblyTitle ("Playground.Android")] 8 | [assembly: AssemblyDescription ("")] 9 | [assembly: AssemblyConfiguration ("")] 10 | [assembly: AssemblyCompany ("")] 11 | [assembly: AssemblyProduct ("")] 12 | [assembly: AssemblyCopyright ("paul")] 13 | [assembly: AssemblyTrademark ("")] 14 | [assembly: AssemblyCulture ("")] 15 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 16 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 17 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 18 | [assembly: AssemblyVersion ("1.0.0")] 19 | // The following attributes are used to specify the signing key for the assembly, 20 | // if desired. See the Mono documentation for more information about signing. 21 | //[assembly: AssemblyDelaySign(false)] 22 | //[assembly: AssemblyKeyFile("")] 23 | 24 | -------------------------------------------------------------------------------- /component/component.yaml: -------------------------------------------------------------------------------- 1 | %YAML 1.2 2 | --- 3 | name: ModernHttpClient 4 | version: 2.4.2 5 | id: "modernhttpclient" 6 | publisher: Paul Betts 7 | publisher-url: http://blog.paulbetts.org/ 8 | summary: Write your app using System.Net.Http, but drop this library in and it will go drastically faster. 9 | license: License.md 10 | details: Details.md 11 | getting-started: GettingStarted.md 12 | icons: 13 | - icon_128x128.png 14 | - icon_512x512.png 15 | libraries: 16 | ios: 17 | - ../build/MonoTouch/ModernHttpClient.dll 18 | ios-unified: 19 | - ../build/Xamarin.iOS10/ModernHttpClient.dll 20 | android: 21 | - ../build/MonoAndroid/ModernHttpClient.dll 22 | is_shell: true 23 | packages: 24 | android: 25 | - Square.OkHttp, Version=2.4.0.3 26 | - modernhttpclient, Version=2.4.2 27 | ios: 28 | - modernhttpclient, Version=2.4.2 29 | ios-unified: 30 | - modernhttpclient, Version=2.4.2 31 | samples: 32 | - name: "HttpClient.iOS Unified API Sample" 33 | path: ../samples/HttpClient.iOS/HttpClient.iOS.sln 34 | - name: "HttpClient.Android Sample" 35 | path: ../samples/HttpClient.Android/HttpClient.Android.sln 36 | ... 37 | -------------------------------------------------------------------------------- /ModernHttpClient.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 2.4.2 5 | Paul Betts 6 | Paul Betts 7 | https://github.com/paulcbetts/ModernHttpClient/blob/master/COPYING 8 | https://github.com/paulcbetts/ModernHttpClient 9 | modernhttpclient 10 | ModernHttpClient 11 | false 12 | Write your app using System.Net.Http, but drop this library in and it will go drastically faster. 13 | Write your app using System.Net.Http, but drop this library in and it will go drastically faster. 14 | Copyright Paul Betts © 2012 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ModernHttpClient 2 | ================ 3 | 4 | This library brings the latest platform-specific networking libraries to 5 | Xamarin applications via a custom HttpClient handler. Write your app using 6 | System.Net.Http, but drop this library in and it will go drastically faster. 7 | This is made possible by two native libraries: 8 | 9 | * On iOS, [NSURLSession](https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLSession_class/Introduction/Introduction.html) 10 | * On Android, via [OkHttp](http://square.github.io/okhttp/) 11 | 12 | ## Usage 13 | 14 | The good news is, you don't have to know either of these two libraries above, 15 | using ModernHttpClient is the most boring thing in the world. Here's how 16 | it works: 17 | 18 | ```cs 19 | var httpClient = new HttpClient(new NativeMessageHandler()); 20 | ``` 21 | 22 | ## How can I use this in a PCL? 23 | 24 | Just reference the Portable version of ModernHttpClient in your Portable 25 | Library, and it will use the correct version on all platforms. 26 | 27 | ## Building 28 | 29 | ```sh 30 | make 31 | ``` 32 | 33 | ## Why doesn't this build in Xamarin Studio? What gives? 34 | 35 | ```sh 36 | ## Run this first 37 | make 38 | ``` 39 | -------------------------------------------------------------------------------- /src/ModernHttpClient/CaptiveNetworkException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | 4 | namespace ModernHttpClient 5 | { 6 | /// 7 | /// Thrown when the request goes to a captive network. This happens 8 | /// usually with wifi networks where an authentication html form is shown 9 | /// instead of the real content. 10 | /// 11 | public class CaptiveNetworkException : WebException 12 | { 13 | const string DefaultCaptiveNetworkErrorMessage = "Hostnames don't match, you are probably on a captive network"; 14 | 15 | /// 16 | /// Gets the source URI. 17 | /// 18 | /// The source URI. 19 | public Uri SourceUri { get; private set; } 20 | 21 | /// 22 | /// Gets the destination URI. 23 | /// 24 | /// The destination URI. 25 | public Uri DestinationUri { get; private set; } 26 | 27 | public CaptiveNetworkException(Uri sourceUri, Uri destinationUri) : base(DefaultCaptiveNetworkErrorMessage) 28 | { 29 | SourceUri = sourceUri; 30 | DestinationUri = destinationUri; 31 | } 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /src/ModernHttpClient/iOS/NativeCookieHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Net; 4 | 5 | #if UNIFIED 6 | using Foundation; 7 | #else 8 | using MonoTouch.Foundation; 9 | #endif 10 | 11 | namespace ModernHttpClient 12 | { 13 | public class NativeCookieHandler 14 | { 15 | public void SetCookies(IEnumerable cookies) 16 | { 17 | foreach (var v in cookies.Select(ToNativeCookie)) { 18 | NSHttpCookieStorage.SharedStorage.SetCookie(v); 19 | } 20 | } 21 | 22 | public List Cookies { 23 | get { 24 | return NSHttpCookieStorage.SharedStorage.Cookies 25 | .Select(ToNetCookie) 26 | .ToList(); 27 | } 28 | } 29 | 30 | static NSHttpCookie ToNativeCookie(Cookie cookie) 31 | { 32 | return new NSHttpCookie(cookie); 33 | } 34 | 35 | static Cookie ToNetCookie(NSHttpCookie cookie) 36 | { 37 | var nc = new Cookie(cookie.Name, cookie.Value, cookie.Path, cookie.Domain); 38 | nc.Secure = cookie.IsSecure; 39 | 40 | return nc; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /samples/HttpClient.Android/DotNet.cs: -------------------------------------------------------------------------------- 1 | // 2 | // This file contains the sample code to use System.Net.WebRequest 3 | // on Android to communicate with HTTP servers 4 | // 5 | // Author: 6 | // Miguel de Icaza 7 | // 8 | 9 | using System; 10 | using System.Net; 11 | using System.Diagnostics; 12 | 13 | namespace HttpClient.Android 14 | { 15 | public class DotNet { 16 | MainActivity ad; 17 | 18 | public DotNet (MainActivity ad) 19 | { 20 | this.ad = ad; 21 | } 22 | 23 | // 24 | // Asynchronous HTTP request 25 | // 26 | public void HttpSample () 27 | { 28 | this.ad.Busy (); 29 | var request = WebRequest.Create (MainActivity.WisdomUrl); 30 | request.BeginGetResponse (FeedDownloaded, request); 31 | } 32 | 33 | // 34 | // Invoked when we get the stream back from the twitter feed 35 | // We parse the RSS feed and push the data into a 36 | // table. 37 | // 38 | void FeedDownloaded (IAsyncResult result) 39 | { 40 | var request = result.AsyncState as HttpWebRequest; 41 | 42 | try { 43 | var response = request.EndGetResponse (result); 44 | this.ad.RenderStream (response.GetResponseStream ()); 45 | } catch (Exception e) { 46 | Debug.WriteLine (e); 47 | } finally { 48 | this.ad.Done (); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Playground.iOS/Playground_iOSViewController.designer.cs: -------------------------------------------------------------------------------- 1 | // WARNING 2 | // 3 | // This file has been generated automatically by Xamarin Studio to store outlets and 4 | // actions made in the UI designer. If it is removed, they will be lost. 5 | // Manual changes to this file may not be handled correctly. 6 | // 7 | using Foundation; 8 | using System.CodeDom.Compiler; 9 | 10 | namespace Playground.iOS 11 | { 12 | [Register ("Playground_iOSViewController")] 13 | partial class Playground_iOSViewController 14 | { 15 | [Outlet] 16 | UIKit.UIProgressView progress { get; set; } 17 | 18 | [Outlet] 19 | UIKit.UILabel md5sum { get; set; } 20 | 21 | [Outlet] 22 | UIKit.UITextView result { get; set; } 23 | 24 | [Action ("cancelIt:")] 25 | partial void cancelIt (Foundation.NSObject sender); 26 | 27 | [Action ("doIt:")] 28 | partial void doIt (Foundation.NSObject sender); 29 | 30 | void ReleaseDesignerOutlets () 31 | { 32 | if (result != null) { 33 | result.Dispose (); 34 | result = null; 35 | } 36 | 37 | if (md5sum != null) { 38 | md5sum.Dispose (); 39 | md5sum = null; 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /samples/HttpClient.iOS/DotNet.cs: -------------------------------------------------------------------------------- 1 | // 2 | // This file contains the sample code to use System.Net.WebRequest 3 | // on the iPhone to communicate with HTTP and HTTPS servers 4 | // 5 | // Author: 6 | // Miguel de Icaza 7 | // 8 | 9 | using System; 10 | using System.Net; 11 | using Foundation; 12 | using System.Security.Cryptography.X509Certificates; 13 | using System.Diagnostics; 14 | 15 | namespace HttpClient 16 | { 17 | public class DotNet { 18 | AppDelegate ad; 19 | 20 | public DotNet (AppDelegate ad) 21 | { 22 | this.ad = ad; 23 | } 24 | 25 | // 26 | // Asynchronous HTTP request 27 | // 28 | public void HttpSample () 29 | { 30 | Application.Busy (); 31 | var request = WebRequest.Create (Application.WisdomUrl); 32 | request.BeginGetResponse (FeedDownloaded, request); 33 | } 34 | 35 | // 36 | // Invoked when we get the stream back from the twitter feed 37 | // We parse the RSS feed and push the data into a 38 | // table. 39 | // 40 | void FeedDownloaded (IAsyncResult result) 41 | { 42 | Application.Done (); 43 | var request = result.AsyncState as HttpWebRequest; 44 | 45 | try { 46 | var response = request.EndGetResponse (result); 47 | ad.RenderStream (response.GetResponseStream ()); 48 | } catch (Exception e) { 49 | Debug.WriteLine (e); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/ModernHttpClient/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ModernHttpClient")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ModernHttpClient")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // Version information for an assembly consists of the following four values: 23 | // 24 | // Major Version 25 | // Minor Version 26 | // Build Number 27 | // Revision 28 | // 29 | // You can specify all the values or you can default the Build and Revision Numbers 30 | // by using the '*' as shown below: 31 | // [assembly: AssemblyVersion("1.0.*")] 32 | [assembly: AssemblyVersion("2.4.2")] 33 | [assembly: AssemblyFileVersion("2.4.2")] 34 | -------------------------------------------------------------------------------- /src/Playground.iOS/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Foundation; 5 | using UIKit; 6 | 7 | namespace Playground.iOS 8 | { 9 | // The UIApplicationDelegate for the application. This class is responsible for launching the 10 | // User Interface of the application, as well as listening (and optionally responding) to 11 | // application events from iOS. 12 | [Register ("AppDelegate")] 13 | public partial class AppDelegate : UIApplicationDelegate 14 | { 15 | // class-level declarations 16 | UIWindow window; 17 | Playground_iOSViewController viewController; 18 | // 19 | // This method is invoked when the application has loaded and is ready to run. In this 20 | // method you should instantiate the window, load the UI into it and then make the window 21 | // visible. 22 | // 23 | // You have 17 seconds to return from this method, or iOS will terminate your application. 24 | // 25 | public override bool FinishedLaunching (UIApplication app, NSDictionary options) 26 | { 27 | window = new UIWindow (UIScreen.MainScreen.Bounds); 28 | 29 | viewController = new Playground_iOSViewController (); 30 | window.RootViewController = viewController; 31 | window.MakeKeyAndVisible (); 32 | 33 | return true; 34 | } 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /samples/HttpClient.iOS/HttpClient.iOS.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClient", "HttpClient.csproj", "{A7833601-70B7-4E22-8CEC-0B822863286D}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|iPhoneSimulator = Debug|iPhoneSimulator 9 | Release|iPhoneSimulator = Release|iPhoneSimulator 10 | Debug|iPhone = Debug|iPhone 11 | Release|iPhone = Release|iPhone 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {A7833601-70B7-4E22-8CEC-0B822863286D}.Debug|iPhone.ActiveCfg = Debug|iPhone 15 | {A7833601-70B7-4E22-8CEC-0B822863286D}.Debug|iPhone.Build.0 = Debug|iPhone 16 | {A7833601-70B7-4E22-8CEC-0B822863286D}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator 17 | {A7833601-70B7-4E22-8CEC-0B822863286D}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator 18 | {A7833601-70B7-4E22-8CEC-0B822863286D}.Release|iPhone.ActiveCfg = Release|iPhone 19 | {A7833601-70B7-4E22-8CEC-0B822863286D}.Release|iPhone.Build.0 = Release|iPhone 20 | {A7833601-70B7-4E22-8CEC-0B822863286D}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator 21 | {A7833601-70B7-4E22-8CEC-0B822863286D}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator 22 | EndGlobalSection 23 | GlobalSection(MonoDevelopProperties) = preSolution 24 | StartupItem = HttpClient.csproj 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /src/ModernHttpClient/Resources/Resource.designer.cs: -------------------------------------------------------------------------------- 1 | #pragma warning disable 1591 2 | // ------------------------------------------------------------------------------ 3 | // 4 | // This code was generated by a tool. 5 | // Mono Runtime Version: 4.0.30319.17020 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | // ------------------------------------------------------------------------------ 11 | 12 | [assembly: Android.Runtime.ResourceDesignerAttribute("ModernHttpClient.Resource", IsApplication=false)] 13 | 14 | namespace ModernHttpClient 15 | { 16 | 17 | 18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] 19 | public partial class Resource 20 | { 21 | 22 | static Resource() 23 | { 24 | global::Android.Runtime.ResourceIdManager.UpdateIdValues(); 25 | } 26 | 27 | public partial class Attribute 28 | { 29 | 30 | static Attribute() 31 | { 32 | global::Android.Runtime.ResourceIdManager.UpdateIdValues(); 33 | } 34 | 35 | private Attribute() 36 | { 37 | } 38 | } 39 | 40 | public partial class String 41 | { 42 | 43 | // aapt resource value: 0x7f020000 44 | public static int library_name = 2130837504; 45 | 46 | static String() 47 | { 48 | global::Android.Runtime.ResourceIdManager.UpdateIdValues(); 49 | } 50 | 51 | private String() 52 | { 53 | } 54 | } 55 | } 56 | } 57 | #pragma warning restore 1591 58 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | MDTOOL ?= /Applications/Xamarin\ Studio.app/Contents/MacOS/mdtool 2 | 3 | .PHONY: all clean 4 | 5 | all: ModernHttpClient.iOS.dll ModernHttpClient.iOS64.dll ModernHttpClient.Android.dll ModernHttpClient.Portable.dll 6 | 7 | package: ModernHttpClient.iOS.dll ModernHttpClient.iOS64.dll ModernHttpClient.Android.dll ModernHttpClient.Portable.dll 8 | mono vendor/nuget/NuGet.exe pack ./ModernHttpClient.nuspec 9 | mv modernhttpclient*.nupkg ./build/ 10 | 11 | ModernHttpClient.Android.dll: 12 | $(MDTOOL) build -c:Release ./src/ModernHttpClient/ModernHttpClient.Android.csproj 13 | mkdir -p ./build/MonoAndroid 14 | mv ./src/ModernHttpClient/bin/Release/MonoAndroid/Modern* ./build/MonoAndroid 15 | 16 | ModernHttpClient.iOS.dll: 17 | $(MDTOOL) build -c:Release ./src/ModernHttpClient/ModernHttpClient.iOS.csproj 18 | mkdir -p ./build/MonoTouch 19 | mv ./src/ModernHttpClient/bin/Release/MonoTouch/Modern* ./build/MonoTouch 20 | 21 | ModernHttpClient.iOS64.dll: 22 | $(MDTOOL) build -c:Release ./src/ModernHttpClient/ModernHttpClient.iOS64.csproj 23 | mkdir -p ./build/Xamarin.iOS10 24 | mv ./src/ModernHttpClient/bin/Release/Xamarin.iOS10/Modern* ./build/Xamarin.iOS10 25 | 26 | ModernHttpClient.Portable.dll: 27 | $(MDTOOL) build -c:Release ./src/ModernHttpClient/ModernHttpClient.Portable.csproj 28 | mkdir -p ./build/Portable-Net45+WinRT45+WP8+WPA81 29 | mv ./src/ModernHttpClient/bin/Release/Portable-Net45+WinRT45+WP8+WPA81/Modern* ./build/Portable-Net45+WinRT45+WP8+WPA81 30 | 31 | clean: 32 | $(MDTOOL) build -t:Clean ModernHttpClient.sln 33 | rm *.dll 34 | rm -rf build 35 | -------------------------------------------------------------------------------- /src/ModernHttpClient/Android/NativeCookieHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Net; 4 | using Java.Net; 5 | 6 | namespace ModernHttpClient 7 | { 8 | public class NativeCookieHandler 9 | { 10 | readonly CookieManager cookieManager = new CookieManager(); 11 | 12 | public NativeCookieHandler() 13 | { 14 | CookieHandler.Default = cookieManager; //set cookie manager if using NativeCookieHandler 15 | } 16 | 17 | public void SetCookies(IEnumerable cookies) 18 | { 19 | foreach (var nc in cookies.Select(ToNativeCookie)) { 20 | cookieManager.CookieStore.Add(new URI(nc.Domain), nc); 21 | } 22 | } 23 | 24 | public List Cookies { 25 | get { 26 | return cookieManager.CookieStore.Cookies 27 | .Select(ToNetCookie) 28 | .ToList(); 29 | } 30 | } 31 | 32 | static HttpCookie ToNativeCookie(Cookie cookie) 33 | { 34 | var nc = new HttpCookie(cookie.Name, cookie.Value); 35 | nc.Domain = cookie.Domain; 36 | nc.Path = cookie.Path; 37 | nc.Secure = cookie.Secure; 38 | 39 | return nc; 40 | } 41 | 42 | static Cookie ToNetCookie(HttpCookie cookie) 43 | { 44 | var nc = new Cookie(cookie.Name, cookie.Value, cookie.Path, cookie.Domain); 45 | nc.Secure = cookie.Secure; 46 | 47 | return nc; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /samples/HttpClient.iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSMainNibFile 6 | MainWindow 7 | CFBundleIconFiles 8 | 9 | Resources/icon-57.png 10 | Resources/icon-114.png 11 | Resources/icon-72.png 12 | Resources/icon-144.png 13 | Resources/icon-29.png 14 | Resources/icon-58.png 15 | Resources/icon-50.png 16 | Resources/icon-100.png 17 | 18 | UIDeviceFamily 19 | 20 | 1 21 | 2 22 | 23 | MinimumOSVersion 24 | 7.0 25 | UISupportedInterfaceOrientations 26 | 27 | UIInterfaceOrientationPortrait 28 | UIInterfaceOrientationLandscapeLeft 29 | UIInterfaceOrientationLandscapeRight 30 | 31 | UISupportedInterfaceOrientations~ipad 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | CFBundleIdentifier 38 | com.modernhttpclient.httpclient 39 | CFBundleDisplayName 40 | HttpClient 41 | CFBundleShortVersionString 42 | 1.0 43 | CFBundleVersion 44 | 1.0 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/Playground.Android/Resources/layout/Main.axml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 30 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /src/ModernHttpClient/iOS/CFNetworkErrors.cs: -------------------------------------------------------------------------------- 1 | #if UNIFIED 2 | using Foundation; 3 | #else 4 | using MonoTouch.Foundation; 5 | using System.Globalization; 6 | #endif 7 | 8 | // These definitions are not currently provided by Xamarin. 9 | // To avoid a potential conflict, these are in a namespace specific to this library. 10 | 11 | namespace ModernHttpClient.CoreFoundation 12 | { 13 | public static class CFNetworkError 14 | { 15 | public static NSString ErrorDomain { get { return new NSString("kCFErrorDomainCFNetwork"); } } 16 | } 17 | 18 | // From Apple reference docs: 19 | // https://developer.apple.com/library/ios/documentation/Networking/Reference/CFNetworkErrors/#//apple_ref/c/tdef/CFNetworkErrors 20 | public enum CFNetworkErrors 21 | { 22 | CFHostErrorHostNotFound = 1, 23 | CFHostErrorUnknown = 2, 24 | 25 | // SOCKS errors 26 | CFSOCKSErrorUnknownClientVersion = 100, 27 | CFSOCKSErrorUnsupportedServerVersion = 101, 28 | 29 | // SOCKS4-specific errors 30 | CFSOCKS4ErrorRequestFailed = 110, 31 | CFSOCKS4ErrorIdentdFailed = 111, 32 | CFSOCKS4ErrorIdConflict = 112, 33 | CFSOCKS4ErrorUnknownStatusCode = 113, 34 | 35 | // SOCKS5-specific errors 36 | CFSOCKS5ErrorBadState = 120, 37 | CFSOCKS5ErrorBadResponseAddr = 121, 38 | CFSOCKS5ErrorBadCredentials = 122, 39 | CFSOCKS5ErrorUnsupportedNegotiationMethod = 123, 40 | CFSOCKS5ErrorNoAcceptableMethod = 124, 41 | 42 | // FTP errors 43 | CFFTPErrorUnexpectedStatusCode = 200, 44 | 45 | // HTTP errors 46 | CFErrorHttpAuthenticationTypeUnsupported = 300, 47 | CFErrorHttpBadCredentials = 301, 48 | CFErrorHttpConnectionLost = 302, 49 | CFErrorHttpParseFailure = 303, 50 | CFErrorHttpRedirectionLoopDetected = 304, 51 | CFErrorHttpBadURL = 305, 52 | CFErrorHttpProxyConnectionFailure = 306, 53 | CFErrorHttpBadProxyCredentials = 307, 54 | CFErrorPACFileError = 308, 55 | CFErrorPACFileAuth = 309, 56 | CFErrorHttpsProxyConnectionFailure = 310, 57 | CFStreamErrorHttpsProxyFailureUnexpectedResponseToConnectMethod = 311, 58 | 59 | // CFURL and CFURLConnection Errors 60 | CFURLErrorUnknown = -998, 61 | CFURLErrorCancelled = -999, 62 | CFURLErrorBadURL = -1000, 63 | CFURLErrorTimedOut = -1001, 64 | CFURLErrorUnsupportedURL = -1002, 65 | CFURLErrorCannotFindHost = -1003, 66 | CFURLErrorCannotConnectToHost = -1004, 67 | CFURLErrorNetworkConnectionLost = -1005, 68 | CFURLErrorDNSLookupFailed = -1006, 69 | CFURLErrorHTTPTooManyRedirects = -1007, 70 | CFURLErrorResourceUnavailable = -1008, 71 | CFURLErrorNotConnectedToInternet = -1009, 72 | CFURLErrorRedirectToNonExistentLocation = -1010, 73 | CFURLErrorBadServerResponse = -1011, 74 | CFURLErrorUserCancelledAuthentication = -1012, 75 | CFURLErrorUserAuthenticationRequired = -1013, 76 | CFURLErrorZeroByteResource = -1014, 77 | CFURLErrorCannotDecodeRawData = -1015, 78 | CFURLErrorCannotDecodeContentData = -1016, 79 | CFURLErrorCannotParseResponse = -1017, 80 | CFURLErrorInternationalRoamingOff = -1018, 81 | CFURLErrorCallIsActive = -1019, 82 | CFURLErrorDataNotAllowed = -1020, 83 | CFURLErrorRequestBodyStreamExhausted = -1021, 84 | CFURLErrorFileDoesNotExist = -1100, 85 | CFURLErrorFileIsDirectory = -1101, 86 | CFURLErrorNoPermissionsToReadFile = -1102, 87 | CFURLErrorDataLengthExceedsMaximum = -1103, 88 | 89 | // SSL errors 90 | CFURLErrorSecureConnectionFailed = -1200, 91 | CFURLErrorServerCertificateHasBadDate = -1201, 92 | CFURLErrorServerCertificateUntrusted = -1202, 93 | CFURLErrorServerCertificateHasUnknownRoot = -1203, 94 | CFURLErrorServerCertificateNotYetValid = -1204, 95 | CFURLErrorClientCertificateRejected = -1205, 96 | CFURLErrorClientCertificateRequired = -1206, 97 | 98 | CFURLErrorCannotLoadFromNetwork = -2000, 99 | 100 | // Download and file I/O errors 101 | CFURLErrorCannotCreateFile = -3000, 102 | CFURLErrorCannotOpenFile = -3001, 103 | CFURLErrorCannotCloseFile = -3002, 104 | CFURLErrorCannotWriteToFile = -3003, 105 | CFURLErrorCannotRemoveFile = -3004, 106 | CFURLErrorCannotMoveFile = -3005, 107 | CFURLErrorDownloadDecodingFailedMidStream = -3006, 108 | CFURLErrorDownloadDecodingFailedToComplete = -3007, 109 | 110 | // Cookie errors 111 | CFHTTPCookieCannotParseCookieFile = -4000, 112 | 113 | // Errors originating from CFNetServices 114 | CFNetServiceErrorUnknown = -72000, 115 | CFNetServiceErrorCollision = -72001, 116 | CFNetServiceErrorNotFound = -72002, 117 | CFNetServiceErrorInProgress = -72003, 118 | CFNetServiceErrorBadArgument = -72004, 119 | CFNetServiceErrorCancel = -72005, 120 | CFNetServiceErrorInvalid = -72006, 121 | CFNetServiceErrorTimeout = -72007, 122 | CFNetServiceErrorDNSServiceFailure = -73000, 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /samples/HttpClient.iOS/HttpClient.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | iPhoneSimulator 6 | 8.0.30703 7 | 2.0 8 | {A7833601-70B7-4E22-8CEC-0B822863286D} 9 | {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10 | Exe 11 | HttpClient 12 | Xamarin.iOS 13 | v1.0 14 | 15 | 16 | True 17 | full 18 | False 19 | bin\iPhoneSimulator\Debug 20 | DEBUG 21 | prompt 22 | 4 23 | True 24 | None 25 | 26 | 27 | i386, x86_64 28 | true 29 | 30 | 31 | none 32 | False 33 | bin\iPhoneSimulator\Release 34 | prompt 35 | 4 36 | None 37 | iPhone Developer 38 | true 39 | 40 | 41 | i386, x86_64 42 | 43 | 44 | True 45 | full 46 | False 47 | bin\iPhone\Debug 48 | DEBUG 49 | prompt 50 | 4 51 | iPhone Developer 52 | True 53 | 54 | 55 | 56 | 57 | ARMv7, ARMv7s, ARM64 58 | true 59 | 60 | 61 | none 62 | False 63 | bin\iPhone\Release 64 | prompt 65 | 4 66 | iPhone Developer 67 | ARMv7, ARMv7s, ARM64 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | ..\..\build\Xamarin.iOS10\ModernHttpClient.dll 83 | 84 | 85 | 86 | 87 | MainWindow.xib 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /src/Playground.iOS/Playground_iOSViewController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CoreGraphics; 3 | using Foundation; 4 | using UIKit; 5 | using System.Net.Http; 6 | using System.Threading; 7 | using System.Diagnostics; 8 | using ModernHttpClient; 9 | using System.Text; 10 | using System.Security.Cryptography; 11 | using System.Threading.Tasks; 12 | using Newtonsoft.Json; 13 | using System.Net; 14 | using System.Linq; 15 | 16 | namespace Playground.iOS 17 | { 18 | public partial class Playground_iOSViewController : UIViewController 19 | { 20 | public Playground_iOSViewController () : base ("Playground_iOSViewController", null) 21 | { 22 | /* 23 | Task.Run (async () => { 24 | var client = new HttpClient(new NSUrlSessionHandler()); 25 | 26 | var item = new { MyProperty = "Property Value" }; 27 | var content = new StringContent(JsonConvert.SerializeObject(item), Encoding.UTF8, "application/json"); 28 | var result = await client.PostAsync("http://requestb.in/1aj9b9c1", content); 29 | 30 | result.EnsureSuccessStatusCode(); 31 | }); 32 | */ 33 | 34 | //This API is only available in Mono and Xamarin products. 35 | //You can filter and/or re-order the ciphers suites that the SSL/TLS server will accept from a client. 36 | //The following example removes weak (export) ciphers from the list that will be offered to the server. 37 | ServicePointManager.ClientCipherSuitesCallback += (protocol, allCiphers) => 38 | allCiphers.Where(x => !x.Contains("EXPORT")).ToList(); 39 | 40 | //Here we accept any certificate and just print the cert's data. 41 | ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => { 42 | System.Diagnostics.Debug.WriteLine("Callback Server Certificate: " + sslPolicyErrors); 43 | 44 | foreach(var el in chain.ChainElements) { 45 | System.Diagnostics.Debug.WriteLine(el.Certificate.GetCertHashString()); 46 | System.Diagnostics.Debug.WriteLine(el.Information); 47 | } 48 | 49 | return true; 50 | }; 51 | 52 | } 53 | 54 | CancellationTokenSource currentToken; 55 | HttpResponseMessage resp; 56 | 57 | partial void cancelIt (Foundation.NSObject sender) 58 | { 59 | this.currentToken.Cancel(); 60 | if (resp != null) resp.Content.Dispose(); 61 | } 62 | 63 | void HandleDownloadProgress(long bytes, long totalBytes, long totalBytesExpected) 64 | { 65 | Console.WriteLine("Downloading {0}/{1}", totalBytes, totalBytesExpected); 66 | 67 | BeginInvokeOnMainThread(() => { 68 | var progressPercent = (float)totalBytes / (float)totalBytesExpected; 69 | progress.SetProgress(progressPercent, animated: true); 70 | }); 71 | } 72 | 73 | async partial void doIt (Foundation.NSObject sender) 74 | { 75 | var handler = new NativeMessageHandler(); 76 | var client = new HttpClient(handler); 77 | 78 | currentToken = new CancellationTokenSource(); 79 | var st = new Stopwatch(); 80 | 81 | st.Start(); 82 | try { 83 | handler.DisableCaching = true; 84 | var url = "https://github.com/paulcbetts/ModernHttpClient/releases/download/0.9.0/ModernHttpClient-0.9.zip"; 85 | 86 | 87 | var request = new HttpRequestMessage(HttpMethod.Get, url); 88 | handler.RegisterForProgress(request, HandleDownloadProgress); 89 | 90 | //if using NTLM authentication pass the credentials below 91 | //handler.Credentials = new NetworkCredential("user","pass"); 92 | 93 | resp = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, currentToken.Token); 94 | result.Text = "Got the headers!"; 95 | 96 | Console.WriteLine("Status code: {0}", resp.StatusCode); 97 | 98 | Console.WriteLine("Reason: {0}", resp.ReasonPhrase); 99 | 100 | Console.WriteLine("Headers"); 101 | foreach (var v in resp.Headers) { 102 | Console.WriteLine("{0}: {1}", v.Key, String.Join(",", v.Value)); 103 | } 104 | 105 | Console.WriteLine("Content Headers"); 106 | foreach (var v in resp.Content.Headers) { 107 | Console.WriteLine("{0}: {1}", v.Key, String.Join(",", v.Value)); 108 | } 109 | 110 | var bytes = await resp.Content.ReadAsByteArrayAsync(); 111 | result.Text = String.Format("Read {0} bytes", bytes.Length); 112 | 113 | var md5 = MD5.Create(); 114 | var md5Result = md5.ComputeHash(bytes); 115 | md5sum.Text = ToHex(md5Result, false); 116 | } catch (Exception ex) { 117 | result.Text = ex.ToString(); 118 | } finally { 119 | st.Stop(); 120 | result.Text = (result.Text ?? "") + String.Format("\n\nTook {0} milliseconds", st.ElapsedMilliseconds); 121 | } 122 | } 123 | 124 | public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation) 125 | { 126 | // Return true for supported orientations 127 | return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown); 128 | } 129 | 130 | public static string ToHex(byte[] bytes, bool upperCase) 131 | { 132 | var result = new StringBuilder(bytes.Length*2); 133 | 134 | for (int i = 0; i < bytes.Length; i++) 135 | result.Append(bytes[i].ToString(upperCase ? "X2" : "x2")); 136 | 137 | return result.ToString(); 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /samples/HttpClient.iOS/MainWindow.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 57 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /src/Playground.iOS/Playground.iOS.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | iPhoneSimulator 6 | 8.0.30703 7 | 2.0 8 | {2CE837CD-9B97-4058-9156-339697EEE228} 9 | {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10 | Exe 11 | Playground.iOS 12 | Resources 13 | PlaygroundiOS 14 | Xamarin.iOS 15 | v1.0 16 | 17 | 18 | true 19 | full 20 | false 21 | bin\iPhoneSimulator\Debug 22 | DEBUG; 23 | prompt 24 | 4 25 | false 26 | None 27 | Entitlements.plist 28 | true 29 | true 30 | true 31 | 32 | 33 | i386, ARM64 34 | 35 | 36 | full 37 | true 38 | bin\iPhoneSimulator\Release 39 | prompt 40 | 4 41 | None 42 | false 43 | Entitlements.plist 44 | 45 | 46 | true 47 | full 48 | false 49 | bin\iPhone\Debug 50 | DEBUG; 51 | prompt 52 | 4 53 | false 54 | Entitlements.plist 55 | true 56 | iPhone Developer 57 | 58 | 59 | 60 | 61 | ARMv7, ARM64 62 | 8.0 63 | 64 | 65 | full 66 | true 67 | bin\iPhone\Release 68 | prompt 69 | 4 70 | Entitlements.plist 71 | false 72 | iPhone Developer 73 | ARMv7, ARM64 74 | 75 | 76 | full 77 | true 78 | bin\iPhone\Ad-Hoc 79 | prompt 80 | 4 81 | false 82 | Entitlements.plist 83 | true 84 | Automatic:AdHoc 85 | iPhone Distribution 86 | ARMv7, ARM64 87 | 88 | 89 | full 90 | true 91 | bin\iPhone\AppStore 92 | prompt 93 | 4 94 | iPhone Distribution 95 | Entitlements.plist 96 | false 97 | Automatic:AppStore 98 | ARMv7, ARM64 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | ..\..\ext\monotouch\Newtonsoft.Json.dll 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | Playground_iOSViewController.cs 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | {6941F069-AC02-40EE-BBF3-9FE3331030EF} 132 | ModernHttpClient.iOS64 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /src/ModernHttpClient/Android/ConcatenatingStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Threading; 5 | using System.Collections.Generic; 6 | using System.Threading.Tasks; 7 | 8 | namespace ModernHttpClient 9 | { 10 | // This is a hacked up version of http://stackoverflow.com/a/3879246/5728 11 | class ConcatenatingStream : Stream 12 | { 13 | readonly CancellationTokenSource cts = new CancellationTokenSource(); 14 | readonly Action onDispose; 15 | 16 | long position; 17 | bool closeStreams; 18 | int isEnding = 0; 19 | Task blockUntil; 20 | 21 | IEnumerator iterator; 22 | 23 | Stream current; 24 | Stream Current { 25 | get { 26 | if (current != null) return current; 27 | if (iterator == null) throw new ObjectDisposedException(GetType().Name); 28 | 29 | if (iterator.MoveNext()) { 30 | current = iterator.Current; 31 | } 32 | 33 | return current; 34 | } 35 | } 36 | 37 | public ConcatenatingStream(IEnumerable> source, bool closeStreams, Task blockUntil = null, Action onDispose = null) 38 | { 39 | if (source == null) throw new ArgumentNullException("source"); 40 | 41 | iterator = source.Select(x => x()).GetEnumerator(); 42 | 43 | this.closeStreams = closeStreams; 44 | this.blockUntil = blockUntil; 45 | this.onDispose = onDispose; 46 | } 47 | 48 | public override bool CanRead { get { return true; } } 49 | public override bool CanWrite { get { return false; } } 50 | public override void Write(byte[] buffer, int offset, int count) { throw new NotSupportedException(); } 51 | public override void WriteByte(byte value) { throw new NotSupportedException(); } 52 | public override bool CanSeek { get { return false; } } 53 | public override bool CanTimeout { get { return false; } } 54 | public override void SetLength(long value) { throw new NotSupportedException(); } 55 | public override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException(); } 56 | 57 | public override void Flush() { } 58 | public override long Length { 59 | get { throw new NotSupportedException(); } 60 | } 61 | 62 | public override long Position { 63 | get { return position; } 64 | set { if (value != this.position) throw new NotSupportedException(); } 65 | } 66 | 67 | public override async Task ReadAsync (byte[] buffer, int offset, int count, CancellationToken cancellationToken) 68 | { 69 | int result = 0; 70 | 71 | if (blockUntil != null) { 72 | await blockUntil.ContinueWith(_ => {}, cancellationToken); 73 | } 74 | 75 | while (count > 0) { 76 | if (cancellationToken.IsCancellationRequested) { 77 | throw new OperationCanceledException(); 78 | } 79 | 80 | if (cts.IsCancellationRequested) { 81 | throw new OperationCanceledException(); 82 | } 83 | 84 | Stream stream = Current; 85 | if (stream == null) break; 86 | 87 | var thisCount = default(int); 88 | thisCount = await stream.ReadAsync(buffer, offset, count, cancellationToken); 89 | 90 | result += thisCount; 91 | count -= thisCount; 92 | offset += thisCount; 93 | if (thisCount == 0) EndOfStream(); 94 | } 95 | 96 | if (cancellationToken.IsCancellationRequested) { 97 | throw new OperationCanceledException(); 98 | } 99 | 100 | if (cts.IsCancellationRequested) { 101 | throw new OperationCanceledException(); 102 | } 103 | 104 | position += result; 105 | return result; 106 | } 107 | 108 | public override int Read (byte[] buffer, int offset, int count) 109 | { 110 | return readInternal(buffer, offset, count); 111 | } 112 | 113 | int readInternal(byte[] buffer, int offset, int count, CancellationToken ct = default(CancellationToken)) 114 | { 115 | int result = 0; 116 | 117 | if (blockUntil != null) { 118 | blockUntil.Wait(cts.Token); 119 | } 120 | 121 | while (count > 0) { 122 | if (ct.IsCancellationRequested) { 123 | throw new OperationCanceledException(); 124 | } 125 | 126 | if (cts.IsCancellationRequested) { 127 | throw new OperationCanceledException(); 128 | } 129 | 130 | Stream stream = Current; 131 | if (stream == null) break; 132 | 133 | var thisCount = default(int); 134 | thisCount = stream.Read(buffer, offset, count); 135 | 136 | result += thisCount; 137 | count -= thisCount; 138 | offset += thisCount; 139 | if (thisCount == 0) EndOfStream(); 140 | } 141 | 142 | position += result; 143 | return result; 144 | } 145 | 146 | protected override void Dispose(bool disposing) 147 | { 148 | if (Interlocked.CompareExchange(ref isEnding, 1, 0) == 1) { 149 | return; 150 | } 151 | 152 | if (disposing) { 153 | cts.Cancel(); 154 | 155 | while (Current != null) { 156 | EndOfStream(); 157 | } 158 | 159 | iterator.Dispose(); 160 | iterator = null; 161 | current = null; 162 | 163 | if (onDispose != null) onDispose(); 164 | } 165 | 166 | base.Dispose(disposing); 167 | } 168 | 169 | void EndOfStream() 170 | { 171 | if (closeStreams && current != null) { 172 | current.Close(); 173 | current.Dispose(); 174 | } 175 | 176 | current = null; 177 | } 178 | } 179 | } 180 | 181 | -------------------------------------------------------------------------------- /src/Playground.Android/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Android.App; 3 | using Android.Content; 4 | using Android.Runtime; 5 | using Android.Views; 6 | using Android.Widget; 7 | using Android.OS; 8 | using System.Net.Http; 9 | using ModernHttpClient; 10 | using System.Threading; 11 | using System.Diagnostics; 12 | using System.Threading.Tasks; 13 | using System.Security.Cryptography; 14 | using System.Text; 15 | using System.Net; 16 | using System.Linq; 17 | using System.IO; 18 | 19 | namespace Playground.Android 20 | { 21 | [Activity (Label = "Playground.Android", MainLauncher = true)] 22 | public class MainActivity : Activity 23 | { 24 | int count = 1; 25 | 26 | CancellationTokenSource currentToken; 27 | 28 | ProgressBar progress; 29 | 30 | void HandleDownloadProgress(long bytes, long totalBytes, long totalBytesExpected) 31 | { 32 | Console.WriteLine("Downloading {0}/{1}", totalBytes, totalBytesExpected); 33 | 34 | RunOnUiThread(() => { 35 | progress.Max = 10000; 36 | 37 | var progressPercent = (float)totalBytes / (float)totalBytesExpected; 38 | var progressOffset = Convert.ToInt32(progressPercent * 10000); 39 | 40 | Console.WriteLine(progressOffset); 41 | progress.Progress = progressOffset; 42 | }); 43 | } 44 | 45 | protected override void OnCreate (Bundle bundle) 46 | { 47 | base.OnCreate (bundle); 48 | 49 | // Set our view from the "main" layout resource 50 | SetContentView (Resource.Layout.Main); 51 | 52 | //This API is only available in Mono and Xamarin products. 53 | //You can filter and/or re-order the ciphers suites that the SSL/TLS server will accept from a client. 54 | //The following example removes weak (export) ciphers from the list that will be offered to the server. 55 | ServicePointManager.ClientCipherSuitesCallback += (protocol, allCiphers) => 56 | allCiphers.Where(x => !x.Contains("EXPORT")).ToList(); 57 | 58 | //Here we accept any certificate and just print the cert's data. 59 | ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => { 60 | System.Diagnostics.Debug.WriteLine("Callback Server Certificate: " + sslPolicyErrors); 61 | 62 | foreach(var el in chain.ChainElements) { 63 | System.Diagnostics.Debug.WriteLine(el.Certificate.GetCertHashString()); 64 | System.Diagnostics.Debug.WriteLine(el.Information); 65 | } 66 | 67 | return true; 68 | }; 69 | 70 | // Get our button from the layout resource, 71 | // and attach an event to it 72 | var button = FindViewById