C# 我可以用什么来代替@?
我申请毕业设计。总之,我需要编写与“body”变量类似的“bodyBefore”变量。我无法翻译它C# 我可以用什么来代替@?,c#,operator-keyword,C#,Operator Keyword,我申请毕业设计。总之,我需要编写与“body”变量类似的“bodyBefore”变量。我无法翻译它 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"; //re
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字符串之间没有区别:
变量的期望值:
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
问题解决了。当我像下面那样编辑“body”变量时,它是有效的
string body = string.Format("{0}={1}&{2}={3}&submit=Login", frm1.txtUserInput.Text, frm1.txtUsername.Text, frm1.txtPassInput.Text, frm1.txtPassword.Text);
谢谢您的帮助。您能详细解释一下您遇到的问题吗?你为什么试图使用“@”?似乎没有任何理由使用“
@”
符号。你认为你为什么需要使用“@reuben-FYI-转义是“倒勾”,而不是“单引号”。当我尝试使用“body”变量发送信息时,它是有效的。但当我尝试使用“bodyBefore”发送信息时,它是有效的“,它无法发送。@AbdullahAlemdar问题不会是由于@
或缺少(它是一个只对解析器有意义的运算符)。请求发送到的端点似乎同时包含用户名
和密码
字段。目前,只有在两个输入字段中逐字输入这些单词,它才会收到这些单词。字符串中每个=
的左侧可能不应由输入确定。