Help Hỏi về lập trình

Renrita

Banned
Joined
Jan 15, 2013
Messages
185
Reactions
49
MR
0.000
Insuree Balance
0
Xin chào các bác :D

Mình không phải dân IT nhưng đang nghiên cứu lập trình 1 số tool nhỏ nhỏ.

Mình đang ngâm cứu C#

nhưng đọc tài liệu, coi video thấy toàn mấy câu lệnh đơn giản if, for, do while ...

Vậy cho mình hỏi để code được tool kiểu như postnews hay multi poster thì đọc tài liệu nào của C# nhỉ ?

Cảm ơn :D
 
không có tài liệu nào hoàn chỉnh để đủ kiến thức làm 1 soft như b nói đâu.

đụng cái nào thì tìm tài liệu cái đó, ví dụ làm soft đó cần giao diện thì tìm tài liệu window form, soft đó post được nhiều bài cùng lúc thì tìm tài liệu multi thread, rồi soft đó giao tiếp với website http thì tìm tài liệu về httpwebrequest, webbrowser,...

:m122:
 
không có tài liệu nào hoàn chỉnh để đủ kiến thức làm 1 soft như b nói đâu.

đụng cái nào thì tìm tài liệu cái đó, ví dụ làm soft đó cần giao diện thì tìm tài liệu window form, soft đó post được nhiều bài cùng lúc thì tìm tài liệu multi thread, rồi soft đó giao tiếp với website http thì tìm tài liệu về httpwebrequest, webbrowser,...

:m122:

Thank pro, cái C# nó rộng vãi đít :D
 
:binhsua136: đi học lên cao học lên tiến sĩ lên hiệp sĩ công nghệ có cái bằng cho oai
tự học làm chi cho mệt
:binhsua139:
 
Mình cũng thích lập trình, nhưng tìm hiểu thấy khó hiểu vãi
 
Xin chào các bác :D

Mình không phải dân IT nhưng đang nghiên cứu lập trình 1 số tool nhỏ nhỏ.

Mình đang ngâm cứu C#

nhưng đọc tài liệu, coi video thấy toàn mấy câu lệnh đơn giản if, for, do while ...

Vậy cho mình hỏi để code được tool kiểu như postnews hay multi poster thì đọc tài liệu nào của C# nhỉ ?

Cảm ơn :D

Theo cậu thì thế nào mới là không đơn giản?
Tất cả mọi tool mình tự viết để phục vụ nhu cầu PTU cá nhân đều chỉ có mấy cái "if, for, do while" đấy thôi :))
Học lập trình quan trọng nhất chính là không được coi thường căn bản!

Còn như PAYPAL86 nói có lý đấy chứ, nếu chỉ cần tool thỏa mãn 1 vài yêu cầu cố định và không cần phát triển nhiều thì bỏ tiền ra mua cho nhanh, đấy là khoản đầu tư hợp lý và làm công việc của bạn trở nên đơn giản hơn, hiệu suất cao hơn, thu hồi lại số vốn bỏ ra đấy nhanh chóng
Thời gian bạn dự định học code có thể dùng để làm việc khác tốt hơn
 
Theo cậu thì thế nào mới là không đơn giản?
Tất cả mọi tool mình tự viết để phục vụ nhu cầu PTU cá nhân đều chỉ có mấy cái "if, for, do while" đấy thôi :))
Học lập trình quan trọng nhất chính là không được coi thường căn bản!

Còn như PAYPAL86 nói có lý đấy chứ, nếu chỉ cần tool thỏa mãn 1 vài yêu cầu cố định và không cần phát triển nhiều thì bỏ tiền ra mua cho nhanh, đấy là khoản đầu tư hợp lý và làm công việc của bạn trở nên đơn giản hơn, hiệu suất cao hơn, thu hồi lại số vốn bỏ ra đấy nhanh chóng
Thời gian bạn dự định học code có thể dùng để làm việc khác tốt hơn

Tại vì mình thấy các cấu trúc đơn giản chỉ có thể dùng để làm mấy chương trình nhỏ nhỏ chạy trên máy tính thôi. Mình muốn hỏi là làm sao để lập trình phần mềm mà nó có thể can thiệp vào web ấy.

Kiểu như bạn làm 1 form đơn giản gồ khung nhập username và password -> khi nhấn nút login trên form thì phần mềm sẽ tự động đăng nhập cho ta trên broswer :). Ý mình muốn hỏi để làm được vậy thì cần những gì :D

Mình gôgle thấy cần httpwebrequest, webservice, multi thread :D nhưng mà ko biết tìm mấy tài liệu đó ở đâu ?
 
B thử vọc class này của mình xem giúp ích gì không :m014:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Drawing;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
using System.Net.Cache;
using System.IO;
using System.Windows.Forms;


namespace MegaTypers_v._1._0._0
{
    class AWebBrowser
    {
        public String proxy = null;


        public CookieContainer cookieContainer = new CookieContainer();


        public Bitmap getImageFromURL(String sURL, CookieContainer cookieContainer, String referer = null)
        {
            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(sURL);
            myRequest.Method = "GET";
            myRequest.CookieContainer = cookieContainer;
            if (referer != null)
                myRequest.Referer = referer;
            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(myResponse.GetResponseStream());
            myResponse.Close();




            this.cookieContainer = myRequest.CookieContainer;


            return bmp;
        }


        public String post(String url_home, String url_post, String strPostData_post, CookieContainer cookieContainer = null, String referer = "http://worker.captchatypers.com/Forms/CaptchaEntry.aspx")
        {
            try
            {
                String strURL = url_post;
                String strPostData = strPostData_post;


                //To allow certs From Web Server
                ServicePointManager.ServerCertificateValidationCallback =
                    delegate(object sender1, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
                    {
                        return false;
                    };
                HttpWebResponse objResponse = null;
                HttpWebRequest objRequest = null;


                objRequest = (HttpWebRequest)WebRequest.Create(strURL);
                WebProxy myProxy = new WebProxy();


                if (this.proxy != null)
                    myProxy.Address = new Uri(this.proxy);


                objRequest.Proxy = myProxy;
                objRequest.Method = "POST";
                objRequest.Referer = referer;


                objRequest.ContentLength = strPostData.Length;
                objRequest.ContentType = "application/x-www-form-urlencoded";


                objRequest.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
                objRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)";
                objRequest.AllowAutoRedirect = true;
                objRequest.MaximumAutomaticRedirections = 4;
                objRequest.MaximumResponseHeadersLength = 4;


                if (cookieContainer == null)
                    objRequest.CookieContainer = this.cookieContainer;
                else
                    objRequest.CookieContainer = cookieContainer;


                // Post the data   
                StreamWriter objWriteToServer = new StreamWriter(objRequest.GetRequestStream());
                try
                {
                    objWriteToServer.Write(strPostData);
                }
                //-3
                catch (Exception e1) { 
                    //MessageBox.Show("-3-Error from streamWriter:{0}", e1.Message); 
                }
                finally { objWriteToServer.Close(); }


                objResponse = (HttpWebResponse)objRequest.GetResponse();


                if (cookieContainer == null)
                    this.cookieContainer.Add(new Uri(url_home), objResponse.Cookies);


                // Retrieve stream response and read it to end
                Stream st = objResponse.GetResponseStream();
                StreamReader sr = new StreamReader(st);
                string source_html = sr.ReadToEnd();






                this.cookieContainer = objRequest.CookieContainer;


                return source_html;
            }
            //-2
            catch (Exception es) {
                //MessageBox.Show("-2-" + es.StackTrace);
            }


            return null;
        }


        public String get(String url, CookieContainer cookiesToContainer = null, String referer = null)
        {
            if (cookiesToContainer == null)
                cookiesToContainer = this.cookieContainer;


            try
            {
                HttpWebRequest requestProfile = (HttpWebRequest)WebRequest.Create(url);
                requestProfile.CookieContainer = cookiesToContainer;
                WebProxy myProxy = new WebProxy();


                if (this.proxy != null)
                    myProxy.Address = new Uri(this.proxy);


                requestProfile.Proxy = myProxy;


                if (referer != null)
                    requestProfile.Referer = referer;
               // requestProfile.Referer = "";


                // Retrieve HttpWebResponse
                HttpWebResponse responseProfile = (HttpWebResponse)requestProfile.GetResponse();


                // Retrieve stream response and read it to end
                Stream st = responseProfile.GetResponseStream();
                StreamReader sr = new StreamReader(st);
                string source_html = sr.ReadToEnd();


                this.cookieContainer = requestProfile.CookieContainer;


                return source_html;
            }
            catch (Exception e) {//MessageBox.Show(e.StackTrace); 
            }


            return null;
        }
    }
}

Ví dụ login vào megatypers

Code:
AWebBrowser webBrowser = new AWebBrowser();
                        
String url_home = "http://www.protypers.com/";
String url_post_login = "http://www.protypers.com/login";

String url_post_value = String.Format("email={0}&password={1}&remember={2}", "điền username", "điền password", "1");
                         
// html_post là đoạn mã html lấy được sau khi gửi request login
String html_post = webBrowser.post(url_home, url_post_login, url_post_value);

if (html_post.IndexOf("login") > 100)
{
      //login thành công
}
else
{
      // sai username, password
}
 
Last edited by a moderator:
Tại vì mình thấy các cấu trúc đơn giản chỉ có thể dùng để làm mấy chương trình nhỏ nhỏ chạy trên máy tính thôi. Mình muốn hỏi là làm sao để lập trình phần mềm mà nó có thể can thiệp vào web ấy.

Kiểu như bạn làm 1 form đơn giản gồ khung nhập username và password -> khi nhấn nút login trên form thì phần mềm sẽ tự động đăng nhập cho ta trên broswer :). Ý mình muốn hỏi để làm được vậy thì cần những gì :D

Mình gôgle thấy cần httpwebrequest, webservice, multi thread :D nhưng mà ko biết tìm mấy tài liệu đó ở đâu ?

Bạn ko tập trung vào căn bản như mình nói, rất khó phát triển đi lên
TUT share trên mạng ko bao giờ hướng dẫn từ a đến z, thường chỉ gãi đúng chỗ ngứa cho bạn lúc cần thôi (ví dụ 1 module nhỏ, cách dùng / tạo 1 vài phương thức mới)
Tham khảo: http://stackoverflow.com/
 

Announcements

Today's birthdays

Forum statistics

Threads
418,637
Messages
7,074,120
Members
170,739
Latest member
topsonvn

Most viewed of week

Most viewed of week

Back
Top Bottom