WebClient.DownloadString("http://website/members/login.php?user=" + textBox1.Text + "&pass=" + textBox2.Text);
을 사용하여 webrequest를 수행하는 개념 증명 프로그램에서 작업 중이며 사용자의 부울 값을 가져 오거나 사용자가 유효한 로그인이 아닌 경우 그것이 실패 알림을주는 열이 아닌 경우 성공 알림을 제공합니까?C# 프로그램이 두 번째 WebClient.DownloadString() 후 응답을 멈 춥니 다.
문제는 처음 시도 할 때 버튼을 눌렀을 때 로그인하는 것입니다.하지만 두 번째 버튼을 다시 누르면 프로그램이 멈추고 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);
}
}
}
'Connect' 메소드 중에'WebRequest'를 닫지 않는 것 같습니다. 이것은 멤버 변수이기 때문에 먼저 적절하게 처리하려고 시도합니다. –
나는 마침내 그것을 이해했다! 내가 잘못 읽고 이것이 Connect 메소드의 응답이었습니다. 감사합니다 :) – connorbp