Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am developing windows mobile application.
in login page i entered user name adn password ang send httprequest to another website. But when i click on second button for download data from that website,then it loss the value of user name and password and don't allow me for download.
Posted

When you create an HttpRequest object, there is a property to allow you to supply credentials. You should create an instance of NetworkCredential with the username and password if the resource you are trying to download requires authentication.

Something like this:

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://some.web.site/some.resource.ext");
NetworkCredential nc = new NetworkCredential("user", "password");
request.Credentials = nc;
 
Share this answer
 
v2
JavaScript
private void AutoLogin()
        {
            string appURL = "http://zl.qq.com/server/webLogin.shtml";
            //string strPostData = String.Format("userName={0}&password={1}",
            //"71444468", "0113,,@tom..com");
            NetworkCredential nc = new NetworkCredential("user", "password");

            // Setup the http request.      
            HttpWebRequest wrWebRequest = WebRequest.Create(appURL) as
            HttpWebRequest;
            wrWebRequest.Method = "post";
            //wrWebRequest.ContentLength = strPostData.Length;
            //wrWebRequest.ContentType = "application/x-www-form-urlencoded";
            wrWebRequest.Credentials = nc;

            CookieContainer cookieContainer = new CookieContainer();
            wrWebRequest.CookieContainer = cookieContainer;

            // Post to the login form.      
            StreamWriter swRequestWriter = new StreamWriter(wrWebRequest.GetRequestStream());
            swRequestWriter.Write(nc);
            swRequestWriter.Close();
            // Get the response.      
            HttpWebResponse hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse();
            // Read the response      
            StreamReader srResponseReader = new
            StreamReader(hwrWebResponse.GetResponseStream());
            string strResponseData = srResponseReader.ReadToEnd();
            srResponseReader.Close();

            
            //Response.Write(strResponseData);
            //return cookieContainer;
        }

response 404,how can i solve?
 
Share this answer
 
v2

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