Hiển thị các bài đăng có nhãn C#. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn C#. Hiển thị tất cả bài đăng

09/07/2022

Gửi tin nhắn lên toàn bộ room chatwork của bạn

 Nếu bạn dùng chatwork và đôi khi muốn gửi 1 thông báo tới tất cả các room/group mà bạn không muốn copy paste thì làm thế nào?

Nếu bạn biết code c#, hãy tham khảo đoạn code sau

Thứ nhất, lấy toàn bộ danh sách room bạn có, trước hết bạn cần có token cá nhân
hãy đăng nhập vào tài khoản chatwork của bạn rồi truy cập link sau để lấy token
https://www.chatwork.com/service/packages/chatwork/subpackages/api/token.php 

=====

//Hàm lấy danh sách room

public partial class ChatworkClient

{

public static List<RoomInfo> GetRooms(string token)

        {

            var client = new RestClient("https://api.chatwork.com/v2/rooms");

            client.Timeout = -1;

            var request = new RestRequest(Method.GET);

            request.AddHeader("X-ChatWorkToken", token);

            IRestResponse response = client.Execute(request);

            //Console.WriteLine(response.Content);

            if(response.IsSuccessful && !string.IsNullOrEmpty(response.Content))

            {

                var rooms = JsonConvert.DeserializeObject<List<RoomInfo>>(response.Content);

                return rooms;

            }

            return null;

        }
}

=====

//model RoomInfo:

public class RoomInfo

    {

        public int room_id { get; set; }

        public string name { get; set; }

    }

======
//Tiếp theo, thực hiện gửi tin nhắn
tham khảo thêm chatwork API: trang 25, 
[POST] /rooms/{room_id}/messages

https://download.chatwork.com/ChatWork_API_Documentation.pdf 

13/04/2022

Error send mail Security.SslState.StartSendAuthResetSignal c#

 Khi code chức năng gửi mail smtp bằng c#

đôi khi thiết lập mail server không chính xác hoặc SSL mail server không hợp lệ

bạn sẽ gặp exception như sau

===

> Source file path:SendMail

  > Source line number:107

   at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)

   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)

   at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)

   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)

   at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)

   at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)

   at System.Net.Mail.SmtpConnection.Flush()

   at System.Net.Mail.ReadLinesCommand.Send(SmtpConnection conn)

   at System.Net.Mail.EHelloCommand.Send(SmtpConnection conn, String domain)

   at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)

   at System.Net.Mail.SmtpClient.GetConnection()

   at System.Net.Mail.SmtpClient.Send(MailMessage message)

===

(*) Cách sửa đơn giản: MailClient sét EnableSsl = false;

02/02/2010

Dùng HtmlAgilityPack bóc tách nội dung trang web với c#

 HtmlAgilityPack là thư viện rất rất mạnh

bạn có thể bóc tách nội dung 1 trang web (1url) bất kỳ rất rất dễ nhé

Đoạn code sau làm ví dụ:
======================================

string url = "https://www.tuandev.com/2010/01/su-dung-task-trong-c.html";

HtmlAgilityPack.HtmlWeb web = new HtmlAgilityPack.HtmlWeb();

HtmlAgilityPack.HtmlDocument htmlDoc = web.Load(url);

//tới đây bạn có 1 htmlDoc hoàn chỉnh rồi

//bạn có thể lấy nội dung trong từng style class như sau

//bằng cách chọn nhiều node SelectNodes hoặc 1 node SelectSingleNode

                var title = htmlDoc.DocumentNode.SelectNodes("//h3[contains(@class, 'post-title')]");

                if(title == null)

                {

                    //do somethings

                }

else{

    //do somethings

}

[Happy coding]

Đăng ký tên miền, hosting, máy chủ, thiết kế lập trình website theo yêu cầu

 Chính thức trở thành đơn vị cung cấp dịch vụ đăng ký tên miền quốc tế, tên miền Việt Nam hosting, máy chủ, cloud hosting, cloud server, ema...