Skip to content

Set up Proxy

Ramtin Jokar edited this page Sep 20, 2020 · 5 revisions

using HttpClientHandler

var proxy = new WebProxy()
{
    Address = new Uri($"proxyHost:proxyPort"), //i.e: http://1.2.3.4.5:8080
    BypassProxyOnLocal = false,
    UseDefaultCredentials = false,

    // *** These creds are given to the proxy server, not the web server ***
    Credentials = new NetworkCredential(
    userName: "proxyUserName",
    password: "proxyPassword")
};

// Now create a client handler which uses that proxy
var httpClientHandler = new HttpClientHandler()
{
    Proxy = proxy,
};

var InstaApi = InstaApiBuilder.CreateBuilder()
                //// Setting up Instagram credentials
                //.SetUser(userSession)
                .UseHttpClientHandler(httpClientHandler)
                .Build();

using HttpClient:

var httpClient = new HttpClient(handler: httpClientHandler, disposeHandler: true)
{
    // if you want to use httpClient, you should set this
    BaseAddress = new Uri("https://i.instagram.com/")
};
var InstaApi = InstaApiBuilder.CreateBuilder()
                //// Setting up Instagram credentials
                //.SetUser(userSession)
                .UseHttpClient(httpClient)
                // if you want to use HttpClient, you have to set this too 
                .UseHttpClientHandler(httpClientHandler)
                .Build();
Clone this wiki locally