本文介绍了如何通过POST参数ASP.Net Web请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使Web请求编程在ASP.NET,使用POST方法。我想与Web请求发送POST参数以及。事情是这样的:
I'm trying to make web requests programmatically in ASP.NET, using the POST method. I'd like to send POST parameters with the web request as well. Something like this:
WebRequest req = WebRequest.Create("accounts.craigslist/login/pstrdr"); req.Method = "POST"; req.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); //WebRequest.Parameters.add("areaabb","hou");显然是注释行不起作用。我如何做到这一点?
obviously the commented line does not work. How do I achieve this?
推荐答案尝试像这样...
string email = "YOUR EMAIL"; string password = "YOUR PASSWORD"; string URLAuth = "accounts.craigslist/login"; string postString = string.Format("inputEmailHandle={0}&name={1}&inputPassword={2}", email, password); const string contentType = "application/x-www-form-urlencoded"; System.Net.ServicePointManager.Expect100Continue = false; CookieContainer cookies = new CookieContainer(); HttpWebRequest webRequest = WebRequest.Create(URLAuth) as HttpWebRequest; webRequest.Method = "POST"; webRequest.ContentType = contentType; webRequest.CookieContainer = cookies; webRequest.ContentLength = postString.Length; webRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1"; webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; webRequest.Referer = "accounts.craigslist"; StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream()); requestWriter.Write(postString); requestWriter.Close(); StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream()); string responseData = responseReader.ReadToEnd(); responseReader.Close(); webRequest.GetResponse().Close();更多推荐
如何通过POST参数ASP.Net Web请求?
发布评论