正确的方式来调用电报api方法

ham*_*med 13 java telegram

我在我的java应用程序中处理Telegram api.我需要使用我的电报帐户进行身份验证和授权,并获取我的特定组的消息列表.为了这个目的,首先我得到了api_id,api_hash并且MTProto servers从电报的网站.其次,我尝试以auth.sendCode这种方式使用方法授权我的帐户:

...
String url = "https://149.154.167.40:443/auth.sendCode";
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-type", "application/x-www-form-urlencoded");
httpPost.addHeader("charset", "UTF-8");

List<NameValuePair> nameValuePairs = new ArrayList<>();
nameValuePairs.add(new BasicNameValuePair("phone_number", myPhoneNumber));
nameValuePairs.add(new BasicNameValuePair("sms_type", "5"));
nameValuePairs.add(new BasicNameValuePair("api_id", api_id));
nameValuePairs.add(new BasicNameValuePair("api_hash", api_hash));
nameValuePairs.add(new BasicNameValuePair("lang_code", "en"));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));

HttpResponse response = httpClient.execute(httpPost);
...
Run Code Online (Sandbox Code Playgroud)

但这会让我感到javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake异常.我测试了url http而不是https和这返回了404 Not Foundhtml内容.在java中调用telegram api方法的正确方法是什么?

更新:

我尝试使用java socket发送TCP post请求,但这会返回给我404 not found.

小智 1

由于它是 mproto 协议,因此您必须遵守他们的规范 - https://core.telegram.org/mtproto

我建议您使用这个项目,因为它有工作示例 - https://github.com/badoualy/kotlogram