wtelegramclient如何应用代理设置?
使用wtelegramclient库编写了一个应用程序。使用代理服务器设置连接到Internet有一项任务: 地址, 港口, 用户名, 密码。
现在,连接是没有代理的。 我们声明变量:
using TL;
private WTelegram.Client _client;
private User _user;
private TelegramSettings telegramSettings = null;
我们用值填充:
private void saveSettingButton_Click(object sender, EventArgs e)
{
if (telegramSettings == null) telegramSettings = new TelegramSettings();
telegramSettings.UseProxy = checkEditUseProxy.Checked;
telegramSettings.ProxyHost = textEditProxyHost.Text.Trim();
telegramSettings.ProxyPort = textEditProxyPort.Text.Trim() == "" ? 0 : Convert.ToInt32(textEditProxyPort.Text.Trim());
telegramSettings.ProxyUserName = textEditProxyUserName.Text.Trim();
telegramSettings.ProxyPassword = textEditProxyPassword.Text.Trim();
telegramSettings.PhoneNumber = (string)textBoxPhone.EditValue;
telegramSettings.API_Hash = textBoxApiHash.Text.Trim();
telegramSettings.API_ID = textBoxApiID.Text.Trim();
}
更改对fig:
string Config(string what)
{
switch (what)
{
case "api_id": return telegramSettings.API_ID;
case "api_hash": return telegramSettings.API_Hash;
case "phone_number": return telegramSettings.PhoneNumber;
case "verification_code":
case "password": // if user has enabled 2FA
BeginInvoke(new Action(() => CodeNeeded(what.Replace('_', ' '))));
_codeReady.Reset();
_codeReady.Wait();
return textBoxCode.Text;
case "first_name":
case "last_name":
return null; // if sign-up is required
default: return null;
};
}
连接
_client = new WTelegram.Client(Config);
_user = await _client.LoginUserIfNeeded();
如何应用代理设置?
An application was written using the WTelegramClient library. There was a task to use the proxy server settings to connect to the Internet:
Address,
Port,
Username,
Password.
Now the connection is made without a proxy.
We declare variables:
using TL;
private WTelegram.Client _client;
private User _user;
private TelegramSettings telegramSettings = null;
We fill it with values:
private void saveSettingButton_Click(object sender, EventArgs e)
{
if (telegramSettings == null) telegramSettings = new TelegramSettings();
telegramSettings.UseProxy = checkEditUseProxy.Checked;
telegramSettings.ProxyHost = textEditProxyHost.Text.Trim();
telegramSettings.ProxyPort = textEditProxyPort.Text.Trim() == "" ? 0 : Convert.ToInt32(textEditProxyPort.Text.Trim());
telegramSettings.ProxyUserName = textEditProxyUserName.Text.Trim();
telegramSettings.ProxyPassword = textEditProxyPassword.Text.Trim();
telegramSettings.PhoneNumber = (string)textBoxPhone.EditValue;
telegramSettings.API_Hash = textBoxApiHash.Text.Trim();
telegramSettings.API_ID = textBoxApiID.Text.Trim();
}
Making changes to the Сonfig:
string Config(string what)
{
switch (what)
{
case "api_id": return telegramSettings.API_ID;
case "api_hash": return telegramSettings.API_Hash;
case "phone_number": return telegramSettings.PhoneNumber;
case "verification_code":
case "password": // if user has enabled 2FA
BeginInvoke(new Action(() => CodeNeeded(what.Replace('_', ' '))));
_codeReady.Reset();
_codeReady.Wait();
return textBoxCode.Text;
case "first_name":
case "last_name":
return null; // if sign-up is required
default: return null;
};
}
Connecting
_client = new WTelegram.Client(Config);
_user = await _client.LoginUserIfNeeded();
How to apply proxy settings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在示例文档文档
在登录之前设置tcphandler:
Using a proxy with WTelegramClient is described in the Examples documentation:
Set TcpHandler before login: