C# 程序在第二个 WebClient.DownloadString() 后停止响应



>我正在开发一个概念验证程序,该程序使用WebClient.DownloadString("http://website/members/login.php?user=" + textBox1.Text + "&pass=" + textBox2.Text);进行网络请求获取布尔值 无论用户是否是有效的登录名,如果是,它会给出成功通知,如果不是十,它会给出失败通知。

问题是当我第一次按下按钮尝试登录时它

工作正常,但是当我再次按下它时,程序冻结并卡在 Webclient.download 字符串上。

如果有人能发现并告诉我出了什么问题,那就太好了。我提供以下代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text;
using System.Net;
using System.IO;
using System.Diagnostics;
using System.Net;
using System.Collections;
namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public static WebClient webclient = new WebClient();
        HttpWebResponse wResp;
        WebRequest wReq;
        bool isConnected = false;
        private String Session = "";
        public Form1()
        {
            InitializeComponent();
        }
        public Boolean checkUser(String username, String password)
        {
                String login = `webclient.DownloadString("http://connorbp.info/members/auth.php?user=" + textBox1.Text + "&pass=" + textBox2.Text);`
                Boolean bLogin = Boolean.Parse(login);
                if (bLogin)
                {
                    Session = username + "-" + password;
                }
                return bLogin;
        }
        public int CanConnect(string dUrl)
        {
            wReq = WebRequest.Create(dUrl);
            int cnt = Connect();
            return cnt;
        }
        private int Connect()
        {
            try
            {
                wResp = (HttpWebResponse)wReq.GetResponse();
                isConnected = true;
                return 1;
            }
            catch (Exception)
            {
                return 0;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int init = CanConnect("http://connorbp.info/members/auth.php");
            if (init == 0)
            {
                notifyIcon1.ShowBalloonTip(200, "CBP Login", "Failed to connect to server! Try again later.", ToolTipIcon.Error);
            }
            else
            {
                if(checkUser(textBox1.Text, textBox2.Text))
                {
                    notifyIcon1.ShowBalloonTip(20, "CBP Login", "Logged In!", ToolTipIcon.Info);
                }
                else
                {
                    notifyIcon1.ShowBalloonTip(20, "CBP Login", "Invalid Username/Password!", ToolTipIcon.Error);
                }
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            this.MaximizeBox = false;
            notifyIcon1.ShowBalloonTip(20, "CBP Login", "for more cool things go to http://connorbp.info", ToolTipIcon.Info);
        }
    }
}

您没有关闭响应。

第二个调用是尝试打开已经打开的东西,因此它挂起。

相关内容

  • 没有找到相关文章

最新更新