我可以用什么代替@?

时间:2015-03-22 05:29:00

标签: c# operator-keyword

我申请毕业设计。总结,我需要写" bodyBefore"变量类似于" body"变量。我无法翻译它。

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/server/login.php");

//request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0";
//request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
//request.Headers.Set(HttpRequestHeader.AcceptLanguage, "tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3");
//request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
request.Referer = "http://localhost/server/index.html";
request.KeepAlive = true;
request.ContentType = "application/x-www-form-urlencoded";

request.Method = "POST";
request.ServicePoint.Expect100Continue = false;

string bodyBefore = frm1.txtUserInput.Text+"="+frm1.txtUsername.Text+"&"+frm1.txtPassInput.Text+"="+frm1.txtPassword.Text+"&"+"submit=Login";
//string body = @bodyBefore;
string body = @"username=admin&password=12345&submit=Login";

MessageBox.Show("Body before : " + bodyBefore+"\nBody"+body);

byte[] postBytes = System.Text.Encoding.UTF8.GetBytes(body);
request.ContentLength = postBytes.Length;
Stream stream = request.GetRequestStream();
stream.Write(postBytes, 0, postBytes.Length);
stream.Close();

body和bodyBefore strings之间没有区别:

enter image description here

对变量的期望:

txtUsername : Textbox of username ///
txtPassword : Textbox of password ///
txtUserInput : Textbox of username input name in web page ///
txtPassInput : Textbox of password input name in web page

1 个答案:

答案 0 :(得分:0)

问题解决了。当我按照下面编辑“body”变量时,它可以工作。

string body = string.Format("{0}={1}&{2}={3}&submit=Login", frm1.txtUserInput.Text, frm1.txtUsername.Text, frm1.txtPassInput.Text, frm1.txtPassword.Text);

感谢您的帮助。