C# WebRequest POST 并获取特定行 - 如何在标签中显示它
C# WebRequest POST and get a specific line - how to display it in label
这是它的图片..也看这里/.. http://prntscr.com/5wadok
string fbid = stTextBox1.Text;
string ukey = stTextBox2.Text;
string jumlah = "4";
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "fbid=" + fbid + "&ukey=" + ukey + "&jumlah=" + jumlah; ;
byte[] data = encoding.GetBytes(postData);
WebRequest request = WebRequest.Create("http://dcvn-full.ga/test/dcgems.php");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
Stream stream = request.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
WebResponse response = request.GetResponse();
stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream);
//MessageBox.Show(sr.ReadToEnd());
stLabel4.Text = (sr.ReadLine());
sr.Close();
stream.Close();
我需要读取 line21to25 并使用此命令或任何其他命令将其显示在 stlabel.5 中,你能帮我吗??
我修改了你的代码如下。希望它能解决您的问题。
string fbid = stTextBox1.Text;
string ukey = stTextBox2.Text;
string jumlah = "4";
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "fbid=" + fbid + "&ukey=" + ukey + "&jumlah=" + jumlah; ;
byte[] data = encoding.GetBytes(postData);
WebRequest request = WebRequest.Create("http://dcvn-full.ga/test/dcgems.php");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (Stream stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
WebResponse response = request.GetResponse();
stream = response.GetResponseStream();
StringBuilder sb = new StringBuilder();
using (StreamReader sr = new StreamReader(stream))
{
int count=1;
while(sr.EndOfStream)
{
string line = sr.ReadLine();
if(count>=21 && count<=25)
{
sb.AppendLine(line);
}
count++;
if (count > 25)
break;
}
stLabel4.Text = (sb.ToString());
}
这是它的图片..也看这里/.. http://prntscr.com/5wadok
string fbid = stTextBox1.Text;
string ukey = stTextBox2.Text;
string jumlah = "4";
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "fbid=" + fbid + "&ukey=" + ukey + "&jumlah=" + jumlah; ;
byte[] data = encoding.GetBytes(postData);
WebRequest request = WebRequest.Create("http://dcvn-full.ga/test/dcgems.php");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
Stream stream = request.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
WebResponse response = request.GetResponse();
stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream);
//MessageBox.Show(sr.ReadToEnd());
stLabel4.Text = (sr.ReadLine());
sr.Close();
stream.Close();
我需要读取 line21to25 并使用此命令或任何其他命令将其显示在 stlabel.5 中,你能帮我吗??
我修改了你的代码如下。希望它能解决您的问题。
string fbid = stTextBox1.Text;
string ukey = stTextBox2.Text;
string jumlah = "4";
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "fbid=" + fbid + "&ukey=" + ukey + "&jumlah=" + jumlah; ;
byte[] data = encoding.GetBytes(postData);
WebRequest request = WebRequest.Create("http://dcvn-full.ga/test/dcgems.php");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (Stream stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
WebResponse response = request.GetResponse();
stream = response.GetResponseStream();
StringBuilder sb = new StringBuilder();
using (StreamReader sr = new StreamReader(stream))
{
int count=1;
while(sr.EndOfStream)
{
string line = sr.ReadLine();
if(count>=21 && count<=25)
{
sb.AppendLine(line);
}
count++;
if (count > 25)
break;
}
stLabel4.Text = (sb.ToString());
}