public InfoResponse GetInfo() { Random myRandom = new Random(); double k = myRandom.NextDouble() * (100000 + 1); string postString = "k=" + k.ToString() + "&action=get_online_info&key=" + k.ToString() + "&async=false"; byte[] postData = Encoding.GetEncoding("GB2312").GetBytes(postString); HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(infourl); myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"; myHttpWebRequest.ContentLength = postData.Length; myHttpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"; myHttpWebRequest.Accept = "*/*"; myHttpWebRequest.Method = "POST"; myHttpWebRequest.CookieContainer = myCookieContainer; try { myHttpWebRequest.GetRequestStream().Write(postData, 0, postData.Length); } catch (Exception ex) { InfoResponse t1 = new InfoResponse(false); return(t1); } HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); StreamReader streamReader = new StreamReader(myHttpWebResponse.GetResponseStream()); string responseContent = streamReader.ReadToEnd(); myHttpWebResponse.Close(); streamReader.Close(); Debug.WriteLine(responseContent); if (responseContent == "not_online") { InfoResponse t1 = new InfoResponse(false); return(t1); } else { InfoResponse t = new InfoResponse(true, responseContent.Split(',')); return(t); } }
private void button4_Click(object sender, EventArgs e) { InfoResponse t = this.hh.GetInfo(); if (t.isSuccess) { string info = "已用流量:\t" + (t.flowG == "0G" ? t.flowM : t.flowG + " " + t.flowM) + "\r\n已用时长:\t" + t.time + "\r\n账户余额:\t" + t.balance + "\r\n当前IP地址:\t" + t.myip; this.infoLable.Text = info; this.notifyIcon1.Text = "IP控制网关-已用" + (t.flowG == "0G" ? t.flowM : t.flowG + " " + t.flowM); } else { MessageBox.Show("信息获取失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void 获取信息ToolStripMenuItem_Click(object sender, EventArgs e) { InfoResponse t = this.hh.GetInfo(); if (t.isSuccess) { string info = "已用流量:\t" + (t.flowG == "0G" ? t.flowM : t.flowG + " " + t.flowM) + "\r\n已用时长:\t" + t.time + "\r\n账户余额:\t" + t.balance + "\r\n当前IP地址:\t" + t.myip; this.infoLable.Text = info; this.notifyIcon1.Text = "IP控制网关-已用" + (t.flowG == "0G" ? t.flowM : t.flowG + " " + t.flowM); this.notifyIcon1.ShowBalloonTip(5000, "账号信息", info, ToolTipIcon.Info); } else { this.notifyIcon1.ShowBalloonTip(5000, "信息获取失败", "信息获取失败", ToolTipIcon.Error); } }