【问题标题】:What can I use instead of @?我可以用什么代替@?
【发布时间】:2015-03-22 05:28:59
【问题描述】:

我申请毕业设计。总结,我需要将“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字符串没有区别:

变量的期望:

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

【问题讨论】:

  • 您能详细解释一下您遇到的问题吗?你为什么要使用'@'?
  • 似乎没有任何理由使用@" 表示法。为什么你认为你需要?
  • @reuben - 仅供参考 - 转义是“反引号”,而不是“单引号”。
  • 当我尝试使用“body”变量发送信息时,它可以工作。但是当我尝试使用“bodyBefore”发送信息时,它无法发送。
  • @AbdullahAlemdar 这个问题不会是由于@ 或缺少(它是一个只对解析器有意义的运算符)。请求发送到的端点似乎需要 usernamepassword 字段。目前,只有当您在两个输入字段中逐字输入这些单词时,它才会接收这些单词。字符串中每个= 的左侧可能不应该由输入确定。

标签: c# operator-keyword


【解决方案1】:

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

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

感谢您的帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多