簡體   English   中英

如何從C#向郵政電報API發送發帖請求?

[英]How do I send a post request to telegram API from C#?

我的電報應用程序帶有應用程序的api_id和應用程序的api_hash。

我使用TLSharp庫實現自己的東西。 但是現在我需要使用此https://core.telegram.org/method/auth.checkPhone電報api方法,但是TLSharp庫中未實現該方法!

我不介意手動完成所有操作,但是我不知道如何操作!

我知道您如何使用C#發送發帖請求,例如:

var response = await client.PostAsync(“ http://www.example.com/index ”,內容);

但在這種情況下,我不會。 因為我不知道:

1)我應該使用哪個鏈接發送帖子請求? 我在電報的網站上找不到它。

2)我應該在那里傳遞什么內容? 應該只是“((auth.checkPhone“ +380666454343”)“”還是整個“((auth.checkPhone” +380666454343“)==(auth.checkedPhonephone_registered:(boolFalse)phone_invited:(boolFalse))”?

那么,如何將這個發帖請求發送到電報api? (不要電報bot API!)

嘗試使用本示例中的System.Net.Http(向服務器的身份驗證請求):

var user = new { login = "your login", password = "your pass" };
string json = JsonConvert.SerializeObject(user);
HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage();
request.RequestUri = new Uri("server route link"); // can be like https://a100.technovik.ru:1000/api/auth/authenticate
request.Method = HttpMethod.Post;
request.Content = content;
HttpResponseMessage response = await client.SendAsync(request);
responseText.Text =  await response.Content.ReadAsStringAsync();

認為 ,從簡短的角度來看,它將更多地遵循您的第二個示例,例如:

var phonenumber = "0123456789";
var content = 
    $@"(auth.checkPhone ""{phonenumber}"")"+
    "=(auth.checkedPhone phone_registered: (boolFalse) phone_invited:(boolFalse))";
var result = DoHttpPost("http://some.example.com/api/etc", content);

(注意:我沒有在此處列出HTTP請求的實際機制,因為其他地方對此進行了詳細介紹-尤其是在提供給您的其他當前答案中; DoHttpPost()不是真正的方法,僅在此處存在作為此過程的占位符)

而且由於此有效負載似乎指示所需的確切功能和參數,因此您只需將其發送到用於所有操作的基本api端點即可,但是我不能肯定地說...

我確實注意到它們似乎確實具有指向該站點上各種應用程序的源代碼的鏈接,所以也許您最好在那兒查找?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM