【发布时间】:2016-02-12 13:05:43
【问题描述】:
我有列表词我需要在 webrequest POST 方法上发送所有这些词 像这儿 : 这个函数请求>
private void RequesteUrl(string word)
{
// try
// {
CookieContainer WeBCookies = new CookieContainer();
HttpWebRequest url = (HttpWebRequest)WebRequest.Create("http://mbc.com/index.php");
url.Method = "POST";
url.UserAgent = "Mozilla/5.0 (Windows NT 10.0; rv:44.0) Gecko/20100101 Firefox/44.0";
url.Referer = "http://mbc.com/index.php?";
var PostData = User.Text + "&password=" + word;
var Data = Encoding.ASCII.GetBytes(PostData);
url.ContentLength = Data.Length;
url.Host = "www.mbc.com";
url.ContentType = "application/x-www-form-urlencoded";
// url.Headers.Add(HttpRequestHeader.Cookie, webBrowser1.Document.Cookie);
url.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
url.KeepAlive = true;
url.Headers.Add("Cookie: "+tryit);
using (var stream = url.GetRequestStream())
{
stream.Write(Data, 0, Data.Length);
}
HttpWebResponse WebResponse = (HttpWebResponse)url.GetResponse();
int status = (int)WebResponse.StatusCode;
Stream ST = WebResponse.GetResponseStream();
StreamReader STreader = new StreamReader(ST);
string RR = STreader.ReadToEnd();
// MessageBox.Show (status.ToString() + " " + word);
// }
// catch (Exception ex)
// {
// MessageBox.Show(ex.Message);
// }
}
我用它来加载:
foreach (string selectword in Lists)
{
RequesteUrl(selectword);
}
但 foreach 没有完成所有列表,他只完成列表中的两个!
【问题讨论】:
标签: c# httpwebrequest