如何在单击时发送多个httpwebrequest [英] how to send multiple httpwebrequest on single click

查看:87
本文介绍了如何在单击时发送多个httpwebrequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Windows移动应用程序。

登录页面我输入了用户名adn密码ang发送httprequest到另一个网站。但是当我点击第二个按钮从该网站下载数据时,它会丢失用户名和密码的值,并且不允许我下载。

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.

推荐答案

创建HttpRequest对象时,有一个属性允许您提供凭据。如果您尝试下载的资源需要身份验证,则应使用用户名和密码创建 NetworkCredential 的实例。



这样的事情:



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;


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



回复404,我该如何解决?


response 404,how can i solve?


这篇关于如何在单击时发送多个httpwebrequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆