【发布时间】:2020-08-20 17:08:51
【问题描述】:
你能帮我解决这个问题吗,我在VS2019中有一个windows窗体,我想获取发送验证码和其他参数(2个参数)后生成的html,我的windows窗体包含devexpress控件,图片编辑在哪里我加载了验证码,textedit1 我在其中放置了验证码,textedit2 我在其中放置了第二个参数(例如 06892898),simplebutton1 在我单击将验证码加载到图片编辑的地方,simplebutton2 使用 2 个参数请求网站,问题是当我在 url 中传递两个参数时,我得到了一个带有消息“会话已完成”的 html,我如何才能在 C# 中获取会话或保持 webclient 对象活动。在此先感谢,这是我的代码:
private WebClient myClient = new WebClient();
public FrmData()
{
InitializeComponent();
}
private void btnCaptcha_Click(object sender, EventArgs e)
{
myClient.DownloadFile(new Uri("http://ww4.essalud.gob.pe:7777/acredita/captcha.jpg"), @"c:\temp\captcha.jpg");
pictureCaptcha.Image = Image.FromFile(@"c:\temp\captcha.jpg");
}
private void btnLoad_Click(object sender, EventArgs e)
{
string line = string.Empty;
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://ww4.essalud.gob.pe:7777/acredita/servlet/Ctrlwacre?captchafield_doc=" + txtedit1.Text + "&td=1&nd=" + txtedit2.Text);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream(), System.Text.Encoding.UTF8);
line = sr.ReadToEnd();
sr.Close();
resp.Close();
XtraMessageBox.Show("" + line);
}
catch (Exception ex)
{
XtraMessageBox.Show("" + ex.Message);
}
}
【问题讨论】:
-
会话 ID 通常存储在 cookie 中。
-
stackoverflow.com/questions/1789627/… 看看这个。我不知道你是否想要永远,但会话会在超时完成后自动重置。
-
谢谢,我只是活着请求网站并获取 html。
-
是否可以使用 webclient 保存 cokkie?