HTTPRequest底层连接已关闭

时间:2013-04-21 11:43:02

标签: c# .net httprequest

我从C#.Net Applcation访问我的身份验证php页面时遇到问题。

它似乎在我的电脑和我的一些用户上正常工作;但是如果我的用户收到错误,我的共同开发者和大约1/3。

错误显示“基础连接已关闭”这已从法语翻译过来,因此可能不准确!

我的代码如下:

    internal string Post(string url, string data)
    {
        string vystup = null;
        try
        {
            //Our postvars
            byte[] buffer = Encoding.ASCII.GetBytes(data);
            //Initialisation, we use localhost, change if appliable
            HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url);
            WebReq.KeepAlive = true;
            WebReq.Expect = "";
            //Our method is post, otherwise the buffer (postvars) would be useless
            WebReq.Method = "POST";
            //We use form contentType, for the postvars.
            WebReq.ContentType = "application/x-www-form-urlencoded";
            //The length of the buffer (postvars) is used as contentlength.
            WebReq.ContentLength = buffer.Length;
            //We open a stream for writing the postvars
            Stream PostData = WebReq.GetRequestStream();
            //Now we write, and afterwards, we close. Closing is always important!
            PostData.Write(buffer, 0, buffer.Length);
            PostData.Close();
            //Get the response handle, we have no true response yet!
            HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
            //Let's show some information about the response
            Console.WriteLine(WebResp.StatusCode);
            Console.WriteLine(WebResp.Server);

            //Now, we read the response (the string), and output it.
            Stream Answer = WebResp.GetResponseStream();
            StreamReader _Answer = new StreamReader(Answer);
            vystup = _Answer.ReadToEnd();

            //Congratulations, you just requested your first POST page, you
            //can now start logging into most login forms, with your application
            //Or other examples.

        }
        catch (Exception ex)
        {
            //MessageBox.Show(ex.Message, "Auth Error");
        }
        return vystup.Trim() + "\n";

    }

页面不会输出任何html标签,如果有帮助,则只输出纯文本。

有没有人有任何想法?如果需要,我可以提供更多信息!

由于

0 个答案:

没有答案