Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hello,
 
i need to access other website which is secured programatically.I dont have any idea in this.can you please help me .
Posted 20-May-12 20:12pm
Comments
ManavGuru at 21-May-12 1:14am
   
you want access another website.
sivasankari ts at 21-May-12 1:18am
   
yes

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

you can use web crawling
 
i.e. use HTTPWebRequest and HTTPWebResponse classes of .net
 

 
 

 
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;
        }
 

 

 
  Permalink  
Comments
sivasankari ts at 21-May-12 1:52am
   
can you please explain.am new to dotnet
Technoses at 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)



Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 21 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100