使用C#在网站上提交表单 [英] Submit form on a website using C#

查看:67
本文介绍了使用C#在网站上提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在尝试使用C#登录briefing.com网站。但是,我将原始登录页面作为回复。我很感激,如果你们中的任何人能够帮助我解决为什么我在成功登录
之后没有收到回复页面。则briefing.com网站提供免费的用户名和密码。用户名test123@gmail.com和密码通行证有效。

I am trying to login to a briefing.com website using C#. However, I am  getting the original login page as response back. I would appreciate if anyone of you could help me with this as to why I am not getting the response page after a successfully loggin in. The briefing.com site provides free username and password. The username test123@gmail.com and password pass are valid.

以下是我的代码: 

Here is my code below: 

  private void Method1()

        {

            //这就是我们发送的内容。
            string post_data =" _textBoxUserName=test123@gmail.com& _textBoxPassword = pass& _checkBoxRememberMe = on" ;;
$


            //这是我们发送的地方

            string uri =" https://www.briefing.com/Login/subscriber.aspx" ;;



            //创建请求

            HttpWebRequest request =(HttpWebRequest)

            WebRequest.Create(URI); request.KeepAlive = false;

            request.ProtocolVersion = HttpVersion.Version10;

            request.Method =" POST"; $


            //将我们的请求字符串转换为字节流

            byte [] postBytes = Encoding.ASCII.GetBytes(post_data);



            //这很重要 - 请确保以这种方式指定类型

            request.ContentType =" application / x-www-form-urlencoded";

            request.ContentLength = postBytes.Length;

           流requestStream = request.GetRequestStream();
$


            //现在发送它¥b $ b            requestStream.Write(postBytes,0,postBytes.Length);

            requestStream.Close();
$


            //抓住响应并将其打印到控制台并附上状态码

            HttpWebResponse response =(HttpWebResponse)request.GetResponse();

            StreamReader sr = new StreamReader(response.GetResponseStream());

            textBox1.Text = sr.ReadToEnd();

            //Console.WriteLine(response.StatusCode);

        }

 private void Method1()
        {
            // this is what we are sending
            string post_data = "_textBoxUserName=test123@gmail.com&_textBoxPassword=pass&_checkBoxRememberMe=on";

            // this is where we will send it
            string uri = "https://www.briefing.com/Login/subscriber.aspx";

            // create a request
            HttpWebRequest request = (HttpWebRequest)
            WebRequest.Create(uri); request.KeepAlive = false;
            request.ProtocolVersion = HttpVersion.Version10;
            request.Method = "POST";

            // turn our request string into a byte stream
            byte[] postBytes = Encoding.ASCII.GetBytes(post_data);

            // this is important - make sure you specify type this way
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = postBytes.Length;
            Stream requestStream = request.GetRequestStream();

            // now send it
            requestStream.Write(postBytes, 0, postBytes.Length);
            requestStream.Close();

            // grab te response and print it out to the console along with the status code
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader sr = new StreamReader(response.GetResponseStream());
            textBox1.Text = sr.ReadToEnd();
            //Console.WriteLine(response.StatusCode);
        }

推荐答案

ASP.NET论坛 http://forums.asp.net 是提出此类问题的最佳地点
The ASP.NET forums http://forums.asp.net is the better place for such questions


这篇关于使用C#在网站上提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆