如何通过POST参数ASP.Net Web请求?

编程入门 行业动态 更新时间:2024-10-28 08:23:53
本文介绍了如何通过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请求?

本文发布于:2023-11-16 08:20:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1602580.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   POST   ASP   Web   Net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!