none
Set proxy on Nano RRS feed

  • Question

  • I went through a question posted here a while back on 'Proxy Authenticating not working

    Today I tried setting proxy (anonymous) up in Nano server (TP5) and it does not work for me. I used below PowerShell code :

    $proxy = '10.35.178.212'
    $port = 3128
    $regKey='HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'
    Set-ItemProperty -path $regKey ProxyEnable -value 1 -ErrorAction Stop
    Set-ItemProperty -path $regKey ProxyServer -value "${Proxy}:${Port}" -ErrorAction Stop

    Now in order to validate that the proxy worked or not, I have to make a web request. So I used httpclient class like below but it blows up :

    [192.168.1.104]: PS > $HttpCLient = New-Object -TypeName System.Net.Http.HttpClient
    [192.168.1.104]: PS > $uri = [uri]::new('http://www.dexterposh.com')
    
    [192.168.1.104]: PS >$response = $HttpCLient.GetAsync($uri)
    
    [192.168.1.104]: PS >$response
    
    
    Result                 :
    Id                     : 279
    Exception              : System.AggregateException: One or more errors occurred. ---> Syste
    m.Net.Http.HttpRequestException: An error occurred while sending the request. --->
                             System.Net.Http.WinHttpException: The operation timed out
                                at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSucce
    ss(Task task)
                                at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess
    AndDebuggerNotification(Task task)
                                at System.Net.Http.WinHttpHandler.<StartRequest>d__103.MoveNext
    ()
                                --- End of inner exception stack trace ---
                                --- End of inner exception stack trace ---
                             ---> (Inner Exception #0) System.Net.Http.HttpRequestException: An
     error occurred while sending the request. ---> System.Net.Http.WinHttpException: The opera
    tion timed
                             out
                                at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSucce
    ss(Task task)
                                at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess
    AndDebuggerNotification(Task task)
                                at System.Net.Http.WinHttpHandler.<StartRequest>d__103.MoveNext
    ()
                                --- End of inner exception stack trace ---<---
                             
    Status                 : Faulted
    IsCanceled             : False
    IsCompleted            : True
    CreationOptions        : None
    AsyncState             :
    IsFaulted              : True
    AsyncWaitHandle        : System.Threading.ManualResetEvent
    CompletedSynchronously : False
    
    
    
    
    

    WinHTTPhandler class object confirms the doubt that proxy is not being set.

    [192.168.1.104]: PS >$winhttphandler = [System.Net.Http.WinHttpHandler]::new()
    [192.168.1.104]: PS >$winhttphandler
    
    
    AutomaticRedirection                : True
    MaxAutomaticRedirections            : 50
    AutomaticDecompression              : GZip, Deflate
    CookieUsePolicy                     : UseInternalCookieStoreOnly
    CookieContainer                     : 
    SslProtocols                        : Tls, Tls11, Tls12
    ServerCertificateValidationCallback : 
    CheckCertificateRevocationList      : False
    ClientCertificateOption             : Manual
    ClientCertificates                  : {}
    PreAuthenticate                     : False
    ServerCredentials                   : 
    WindowsProxyUsePolicy               : UseWinHttpProxy
    DefaultProxyCredentials             : System.Net.SystemNetworkCredential
    Proxy                               : 
    MaxConnectionsPerServer             : 2147483647
    ConnectTimeout                      : 00:01:00
    SendTimeout                         : 00:00:30
    ReceiveHeadersTimeout               : 00:00:30
    ReceiveDataTimeout                  : 00:00:30
    MaxResponseHeadersLength            : 65536
    MaxResponseDrainSize                : 65536
    So my question is how to set proxy on Nano server ?



    Knowledge is Power{Shell}

    DexterPOSH

    My Blog

    Friday, May 13, 2016 10:56 AM

All replies

  • When creating a new HttpClient object using the default constructor, a WinHttpHandler will be created internally with the "WindowsProxyUsePolicy" property set to be "UseWinInetProxy" (see HttpClientHandler.Windows.cs), so by default, it should use the IE proxy registry settings.

    But the settings for IE proxy are by default per user, and according to this post, you need to set the following registry property if you want to enforce machine-wide WinINET proxy settings.

    • HKLM\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings
      DWORD: ProxySettingsPerUser = 0 

    Can you try to set the user-wide proxy settings (in HKCU) and see if that works?

    You can also try using "UseWinHttpProxy" for the "WindowsProxyUsePolicy" property by passing in your WinHttpHandler to HttpClient constructor. The same post also introduces how to set WinHttp proxy settings.

    Friday, May 13, 2016 6:15 PM
  • Hmmm.....I tried setting the same in the HKCU hive along with the ProxySettingsPerUser, but I still see the same error.
    Thanks for your response.

    Knowledge is Power{Shell}

    DexterPOSH

    My Blog

    Monday, May 16, 2016 5:05 AM
  • Hi Dexter,

    Were you able to find a solution for this? I am also facing the same issue getting Internet on Nano server through proxy servers.

    Thanks.

    Monday, May 8, 2017 1:08 PM
  • if im not mistaken .. ive read somewhere that nano doesnt support any kind of proxy ... it was totally stripped out from http.sys i guess... this is exactly what turned me off 

    SunChero


    Arguing on the net is like special olympics, Even if you win, you re still retarded

    Thursday, November 2, 2017 1:16 PM