1 ضمیمه
اتصال به تلگرام با api-id , api-hash از طریق سی شارپ
به عرض سلام خدمت دوستان عزیز من با استفاده از کتابخانه tlsharp قصد دارم چک کنم که یک شماره در تلگرام قبلا ثبت شده یا نه
برای این کار قطعه کد زیر را ثبت کردم ( برای انجام مراحل بعدی مشکلی ندارم ) ولی وقتی برنامه را اجرا می کنم با خطا مواجه می شم کسی هست که بدونه دلیل این خطا چیه ؟
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TLSharp.Core;
namespace ConsoleApplication4
{
class Program
{
private static int apiID = ------;
private static string apiHash = "**********************";
static void Main(string[] args)
{
Task.Run(()=>TestUserInTelegramRegister());
Console.ReadLine();
}
static async Task TestUserInTelegramRegister()
{
var store = new FileSessionStore();
try
{
var client = new TelegramClient(apiID, apiHash, store, "session", null);
await client.ConnectAsync();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}
کد HTML:
<p style="color:red">
error:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 149.154.175.100:443
</p>
ضمیمه 148332
نقل قول: اتصال به تلگرام با api-id , api-hash از طریق سی شارپ
فیلترشکنتون رو روشن کنید ببینید باز هم این خطا میاد؟
نقل قول: اتصال به تلگرام با api-id , api-hash از طریق سی شارپ
آره فری گیت رو نصب کردم روشن می کنم بازم همین خطا رو میده
نقل قول: اتصال به تلگرام با api-id , api-hash از طریق سی شارپ
سلام
من هم دقیقا همین مشکل رو دارم
قبل از این که تلگرام فیلتر بشه برنامه کار میکرد ولی الان با فیلتر شکن هم کار نمیکنه.
فکر کنم برای اتصال باید از پروکسی استفاده کرد.
کسی نحوه اتصال با پروکسی رو تو tlsharp میدونه؟
نقل قول: اتصال به تلگرام با api-id , api-hash از طریق سی شارپ
سلام دوستان ی راه حل براش پیدا کردم
با استفاده از قطعه که زیر مشکل حل خواهد شد .
TcpClient tcp = conectarProxy(httpProxyHost, httpProxyPort);
client = new TelegramClient(appId, appHash, null, null, new TcpClientConnectionHandler(tcp);
private static TcpClient conectarProxy(string httpProxyHost, int httpProxyPort)
{
var url = "http://" + httpProxyHost + ":" + httpProxyPort;
var proxyUrl = WebRequest.DefaultWebProxy.GetProxy(new Uri(url));
WebResponse response = null;
var tentativas = 10;
while (tentativas >= 0)
{
var request = (HttpWebRequest)WebRequest.Create(url);
request.KeepAlive = true;
var webProxy = new WebProxy(proxyUrl);
request.Proxy = webProxy;
request.Method = "CONNECT";
request.Timeout = 3000;
tentativas--;
try
{
response = request.GetResponse();
break;
}
catch (Exception ex)
{
if (tentativas >= 0 && ex.Message.Equals("The operation has timed out", StringComparison.InvariantCultureIgnoreCase))
{
Console.WriteLine("Ocorreu timeout ao tentar se conectar pelo proxy.");
}
else
{
throw new Exception("Algo deu errado", ex);
}
}
}
var responseStream = response.GetResponseStream();
Debug.Assert(responseStream != null);
const BindingFlags Flags = BindingFlags.NonPublic | BindingFlags.Instance;
var rsType = responseStream.GetType();
var connectionProperty = rsType.GetProperty("Connection", Flags);
var connection = connectionProperty.GetValue(responseStream, null);
var connectionType = connection.GetType();
var networkStreamProperty = connectionType.GetProperty("NetworkStream", Flags);
var networkStream = networkStreamProperty.GetValue(connection, null);
var nsType = networkStream.GetType();
var socketProperty = nsType.GetProperty("Socket", Flags);
var socket = (Socket)socketProperty.GetValue(networkStream, null);
return new TcpClient { Client = socket };
}
client = new TelegramClient(appId, appHash, null, null, new TcpClientConnectionHandler(tcp));
نقل قول: اتصال به تلگرام با api-id , api-hash از طریق سی شارپ
نقل قول:
نوشته شده توسط
vahidjafarzadeh
سلام دوستان ی راه حل براش پیدا کردم
با استفاده از قطعه که زیر مشکل حل خواهد شد .
TcpClient tcp = conectarProxy(httpProxyHost, httpProxyPort);
client = new TelegramClient(appId, appHash, null, null, new TcpClientConnectionHandler(tcp);
private static TcpClient conectarProxy(string httpProxyHost, int httpProxyPort)
{
var url = "http://" + httpProxyHost + ":" + httpProxyPort;
var proxyUrl = WebRequest.DefaultWebProxy.GetProxy(new Uri(url));
WebResponse response = null;
var tentativas = 10;
while (tentativas >= 0)
{
var request = (HttpWebRequest)WebRequest.Create(url);
request.KeepAlive = true;
var webProxy = new WebProxy(proxyUrl);
request.Proxy = webProxy;
request.Method = "CONNECT";
request.Timeout = 3000;
tentativas--;
try
{
response = request.GetResponse();
break;
}
catch (Exception ex)
{
if (tentativas >= 0 && ex.Message.Equals("The operation has timed out", StringComparison.InvariantCultureIgnoreCase))
{
Console.WriteLine("Ocorreu timeout ao tentar se conectar pelo proxy.");
}
else
{
throw new Exception("Algo deu errado", ex);
}
}
}
var responseStream = response.GetResponseStream();
Debug.Assert(responseStream != null);
const BindingFlags Flags = BindingFlags.NonPublic | BindingFlags.Instance;
var rsType = responseStream.GetType();
var connectionProperty = rsType.GetProperty("Connection", Flags);
var connection = connectionProperty.GetValue(responseStream, null);
var connectionType = connection.GetType();
var networkStreamProperty = connectionType.GetProperty("NetworkStream", Flags);
var networkStream = networkStreamProperty.GetValue(connection, null);
var nsType = networkStream.GetType();
var socketProperty = nsType.GetProperty("Socket", Flags);
var socket = (Socket)socketProperty.GetValue(networkStream, null);
return new TcpClient { Client = socket };
}
client = new TelegramClient(appId, appHash, null, null, new TcpClientConnectionHandler(tcp));
این تابع خروجی اش از نوع TcpClient هست ولی ورودی TelegramClient از نوع TcpClientConnectionHandler هست و خطا میده در این خط روی شی tcp
client = new TelegramClient(appId, appHash, null, null, new TcpClientConnectionHandler(tcp));[/QUOTE]
نقل قول: اتصال به تلگرام با api-id , api-hash از طریق سی شارپ
ممنون از انجمن عالی تون.مطالبش بسیار کامل و جامع هست.موفق باشید.
اگر علاقه مند به مباحث مربوط به طراحی و بهینه سازی وب سایت هستید از پیج های ما بازدید کنید:
طراحی سایت در تبریز
طراحی اپلیکیشن در تبریز
طراحی لوگو در تبریز
سئو در تبریز