Search code examples
neo4jclient

How to use a proxy with the C# Neo4jClient?


How does one route Neo4jClient connections through a proxy?

The client accepts an IHttpClient in the GraphClient constructor except that is an internal type which doesn't expose any proxy properties


Solution

  • The code below works as of 1.1.0.32 where proxyUri would be something like http://myproxy.net:8080

    var graphUri = new Uri(ConnectionConfig.GraphUri);
    var httpClientHandler = new HttpClientHandler();
    
    httpClientHandler.Proxy = new WebProxy(ConnectionConfig.ProxyUri, true);
    httpClientHandler.UseProxy = true;
    
    var httpClient = new HttpClient(httpClientHandler);
    var httpClientWrapper = new HttpClientWrapper(ConnectionConfig.Username, ConnectionConfig.Password, httpClient);
    _graphClient = new GraphClient(graphUri, httpClientWrapper);