-
Notifications
You must be signed in to change notification settings - Fork 245
Set up Proxy
Ramtin Jokar edited this page Aug 7, 2018
·
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,
};
bool needServerAuthentication = false;
// Omit this part if you don't need to authenticate with the web server:
if (needServerAuthentication)
{
httpClientHandler.PreAuthenticate = true;
httpClientHandler.UseDefaultCredentials = false;
// *** These creds are given to the web server, not the proxy server ***
httpClientHandler.Credentials = new NetworkCredential(
userName: "serverUserName",
password: "serverPassword");
}
var InstaApi = InstaApiBuilder.CreateBuilder()
//// Setting up Instagram credentials
//.SetUser(userSession)
.UseHttpClientHandler(httpClientHandler)
.Build();using your custom HttpClient:
var httpClient = new HttpClient(handler: httpClientHandler, disposeHandler: true);
var InstaApi = InstaApiBuilder.CreateBuilder()
//// Setting up Instagram credentials
//.SetUser(userSession)
.UseHttpClient(httpClient)
.Build();Iranian Developers (c) 2021 | Bahar 1400