Click here to Skip to main content
15,561,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

i need to access other website which is secured programatically.I dont have any idea in this.can you please help me .
Posted
Comments
ManavGuru 21-May-12 1:14am    
you want access another website.
sivasankari ts 21-May-12 1:18am    
yes

1 solution

you can use web crawling

i.e. use HTTPWebRequest and HTTPWebResponse classes of .net



C#
function go()
{
	ccCookie = new CookieContainer();
        StringBuilder sb = new StringBuilder();

        string sMemberDetail = "";
        string sFormDetail = "";
        string sScript = "";

      
        sParameters = "username=" + sUserId + "&password=" + Uri.EscapeDataString(sPassWd) + "&submit=Sign+In";
        sResponse = fm.GetWebResponseString("http://ewebss.in/index.php", "http://eswebss.in/index.php", "POST", "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, */*", ccCookie, "application/x-www-form-urlencoded", sParameters);


        if (sResponse.Contains("Login") && sResponse.Contains("User Name"))
        {
            
            ltrProcess.Text = "Invalid UserId or Password";
            return;
        }

}


 
        public string GetWebResponseString(string Url, string Referer, string Method, string Accept, CookieContainer ccCookie, string ContentType, string PostData)
        {
            string strPageOutput = string.Empty;
            try
            {
                HttpWebResponse response = GetWebResponse(Url, Referer, Method, Accept, ccCookie, ContentType, PostData, false);

                strPageOutput = new StreamReader(response.GetResponseStream()).ReadToEnd();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return strPageOutput;
        }




        public HttpWebResponse GetWebResponse(string Url, string Referer, string Method, string Accept, CookieContainer ccCookie, string ContentType, string PostData, bool microsoftajaxDelta)
        {
             
            HttpWebResponse response = null;
            HttpWebRequest request = null;

            try
            {
                request = (HttpWebRequest)WebRequest.Create(Url);

                request.ServicePoint.Expect100Continue = false;
                request.KeepAlive = true;

                if (microsoftajaxDelta) request.Headers.Add("x-microsoftajax", "Delta=true");
                if (Referer != null && Referer != "") request.Referer = Referer;
                if (Method != null && Method != "") request.Method = Method;
                if (Accept != null && Accept != "") request.Accept = Accept;
                if (ContentType != null && ContentType != "") request.ContentType = ContentType;
                if (ccCookie != null) request.CookieContainer = ccCookie;
                request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729)";

                request.Timeout = 60000;

                if (PostData != null && PostData != "")
                {
                    request.ContentLength = (long)PostData.Length;

                    using (Stream objStream = request.GetRequestStream())
                    {
                        byte[] arrpostData = System.Text.Encoding.ASCII.GetBytes(PostData);
                        objStream.Write(arrpostData, 0, arrpostData.Length);
                        objStream.Close();
                    }
                }

                response = (HttpWebResponse)request.GetResponse();
            }
            catch (Exception ex)
            {
                Exception exStatus = new Exception("Error Occured While Resolving Url : " + Url + Environment.NewLine + "Error Message : " + ex.Message, ex.InnerException);
                throw exStatus;
            }
            return response;
        }
 
Share this answer
 
Comments
sivasankari ts 21-May-12 1:52am    
can you please explain.am new to dotnet
Technoses 21-May-12 12:17pm    
in above process
we use httpwebrequest to access website

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900