locked
StreamSocket and web proxies

    Question

  • Hello,

    I'm facing the need to use a StreamSocket through a web proxy and based on the StreamSocket documentation as long as a HttpClient instance was previously successfully authenticated with the proxy and the credentials used for the authentication are still valid, the StreamSocket should be able to use the same web proxy automatically and transparently. I've tried using a HttpClient instance to make a HTTP call through the web proxy just before using the StreamSocket object but the StreamSocket fails at reaching the remote host.

    I would very much like to use a HTTP networking class (e.g. HttpClient) instead of the StreamSocket class but what is retuned does not comply to the HTTP protocol spec reason why a "The server committed a protocol violation. section=responsestatusline" exception would otherwise be thrown.

    Has anyone faced the need to use a StreamSocket via a web proxy?

    Any suggestion?

    Thx,

    Steve

    Monday, May 19, 2014 12:19 PM

Answers

  • Can you trace the calls made with fiddler or Microsoft's network monitor?

    You should be able to see the proxy being used, proxy headers/authentication process - and finally a web page. 

    You'll probably also see some HTTP CONNECT header when your StreamSocket then starts it's connection.  IF your system supports Http/connect proxying in the first place, that is.


    Darin R.

    Tuesday, May 20, 2014 10:13 PM

All replies

  • Have you tried the new (in 8.1) Windows.Web.HttpClient?  It's got a similar programming model to the System.Net one, but it's more compatible with web sites and proxies. 

    Most of the compat issues I've seen with System.Net HttpClient are resolved with the Windows.Web.Http HttpClient.

    There's a poster that shows the entire WW HttpClient API; you can download it here


    Network Developer Experience Team (Microsoft)

    Monday, May 19, 2014 4:29 PM
  • Hello,

    thank you, I already had the poster and unfortunately HttpClient in Windows 8.1 cannot be used because as I said I'm trying to retrieve a non HTTP resource (the response does not start a HTTP/1.1....) reason why the "The server committed a protocol violation. section=responsestatusline" exception is raised.

    I wonder, what should be used in the case a non HTTP resource is being retrieved and yet communication needs to go through a web proxy? Sockets don't expose support for proxies while on the other hand web/HTTP related networking classes complain about non HTTP responses being returned.

    I must say I'm lost at this point :(

    Thx

    Steve



    Monday, May 19, 2014 9:38 PM
  • From the StreamSocket documentation:

    Support for authenticating proxies

    In a Windows Store app the StreamSocket class supports connecting to a remote endpoint when authenticating proxies are required to plumb the connection. This support for authenticating proxies only works if Internet Explorer or an app that uses the HttpClient class in the Windows.Web.Http namespace has previously successfully authenticated with the proxy and the credentials previously used for the authentication are still valid. This support does not work if a web browser other than Internet Explorer was used to provide the authentication credentials to the proxy.


    As I said I tried using a HttpClient object to make a request through the web proxy hoping that a subsequent call to the StreamSocket object would transparently use the same web proxy but it does not seem to work. Did I misinterpret the documentation?

    Thx

    Steve



    Monday, May 19, 2014 9:44 PM
  • Can you trace the calls made with fiddler or Microsoft's network monitor?

    You should be able to see the proxy being used, proxy headers/authentication process - and finally a web page. 

    You'll probably also see some HTTP CONNECT header when your StreamSocket then starts it's connection.  IF your system supports Http/connect proxying in the first place, that is.


    Darin R.

    Tuesday, May 20, 2014 10:13 PM