Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Missing feature: ClientWebSocket does not support proxies or authentication. #12758

@dalexsoto

Description

@dalexsoto

From @cosminstirbu on February 1, 2019 11:48

Steps to Reproduce

  1. Configure a proxy on your macOS (such as Charles)
  2. Run the following code in the iOS Simulator
        public async void Connect()
        {
            var settings = CFNetwork.GetSystemProxySettings();

            string host = settings.HTTPProxy;
            int port = settings.HTTPPort;

            var ws = new ClientWebSocket();
            ws.Options.Proxy = new WebProxy(host, port);

            //  Non SSL
            //await ws.ConnectAsync(new Uri("ws://echo.websocket.org"), CancellationToken.None);

            //  SSL
            await ws.ConnectAsync(new Uri("wss://echo.websocket.org"), CancellationToken.None);

            var messageBytes = Encoding.UTF8.GetBytes("Hello world!");

            var sendArraySegment = new ArraySegment<byte>(messageBytes);

            await ws.SendAsync(sendArraySegment, WebSocketMessageType.Text, true, CancellationToken.None);

            var receiveBuffer = new byte[1024];
            var receiveArraySegment = new ArraySegment<byte>(receiveBuffer);

            var result = await ws.ReceiveAsync(receiveArraySegment, CancellationToken.None);

            var receiveMessage = Encoding.UTF8.GetString(receiveBuffer, 0, result.Count);
            Debug.Write(receiveMessage);
        }
  1. Notice that the web socket is not being recorded by Charles.

Expected Behavior

The ClientWebSocket should use the Options.Proxy property. The requests aren't recorded by Charles, and even if I hardcode a dummy host and a dummy port, no exception is thrown by the ConnectAsync method.

Actual Behavior

The ClientWebSocket connects and sends all the data without taking into account the proxy.

Environment

Visual Studio Enterprise 2017 for Mac
Version 7.7.4 (build 1)
Installation UUID: 1ede8c5d-9d75-419f-82a5-a4e553d2c07f
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)

	Package version: 516000221

Mono Framework MDK
Runtime:
	Mono 5.16.0.221 (2018-06/b63e5378e38) (64-bit)
	Package version: 516000221

NuGet
Version: 4.8.0.5385

.NET Core
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	2.1.6
	2.1.2
	2.1.1
	2.0.5
	2.0.0
	1.1.2
	1.0.5
SDK: /usr/local/share/dotnet/sdk/2.1.500/Sdks
SDK Versions:
	2.1.500
	2.1.302
	2.1.301
	2.1.4
	2.0.0
	1.0.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/msbuild/15.0/bin/Sdks

Xamarin.Profiler
Version: 1.6.4
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater
Version: 11

Xamarin.Android
Version: 9.1.5.1 (Visual Studio Enterprise)
Android SDK: /Users/cosminstirbu/Documents/sdk
	Supported Android versions:
		4.4 (API level 19)
		5.1 (API level 22)
		6.0 (API level 23)
		7.0 (API level 24)
		7.1 (API level 25)
		8.0 (API level 26)
		8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.0
SDK Build Tools Version: 28.0.3

Microsoft Mobile OpenJDK
Java SDK: /Users/cosminstirbu/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.9
openjdk version "1.8.0-9"
OpenJDK Runtime Environment (build 1.8.0-9-microsoft-b00)
OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Android Device Manager
Version: 7.7.5.0
Hash: 06ceaea1

Apple Developer Tools
Xcode 10.1 (14460.46)
Build 10B61

Xamarin.Mac
Version: 5.2.1.13 (Visual Studio Enterprise)
Hash: a4332c90
Branch: 
Build date: 2019-01-11 13:08:10-0500

Xamarin.iOS
Version: 12.2.1.13 (Visual Studio Enterprise)
Hash: a4332c90
Branch: d15-9
Build date: 2019-01-11 13:08:09-0500

Xamarin Inspector
Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

Build Information
Release ID: 707040001
Git revision: 2a4679454f31c8bb887cfd181ea133c9149d3cad
Build date: 2019-01-30 16:18:21+00
Build branch: release-7.7.4
Xamarin extensions: c8b4305fd4c60b9c25947072eb150fdc3a5aa2b5

Operating System
Mac OS X 10.14.0
Darwin 18.0.0 Darwin Kernel Version 18.0.0
    Wed Aug 22 20:13:40 PDT 2018
    root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64

Enabled user installed extensions
AddinMaker 1.4.3
FileNesting 0.1.1
Macaque Tips 0.1.2
StyleCop Support 1.1.0.0
xUnit.NET 2 testing framework support 0.7.5
Redth's Addins 1.0.9
Straight8's SpecFlow Integration 1.11.2.0
Internet of Things (IoT) development (Preview) 7.5.3

Example Project (If Possible)

ClientWebSocket-Proxy.zip

Copied from original issue: dotnet/macios#5527

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions