【问题标题】:C# WebRequest POST and get a specific line - how to display it in labelC# WebRequest POST 并获取特定行 - 如何在标签中显示它
【发布时间】:2015-01-24 02:37:06
【问题描述】:

这是它的图片..也看这里/..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 中显示它,你能帮帮我吗?

【问题讨论】:

    标签: c# post response webrequest


    【解决方案1】:

    我将您的代码修改如下。希望它能解决您的问题。

            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());
            }
    

    【讨论】:

    • 将此行更改为 var stream = response.GetResponseStream();
    猜你喜欢
    • 1970-01-01
    • 2012-09-14
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    • 1970-01-01
    • 2021-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多