【问题标题】:passing Parameters(such as form feeds) to Website from WinForm(C#)从 WinForm(C#) 向网站传递参数(例如表单提要)
【发布时间】:2011-05-30 21:40:56
【问题描述】:

我正在学习 C#。我试图创建一个应用程序来通过要求用户输入他的卷号来获取考试结果。

我知道我必须使用 httpwebrequest 或类似的名称。

这里是result.php页面的源页面sn-p

<form action="resultstatus.php" method="post" name="myform" id="myform">
   <p align="center">
      <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
      <span class="style6">Please enter your Application Number or Registration Number </span>
      <input type="text" name="regno" size="12" maxlength="10" />
      <input type="submit" name="submit" value="Submit" onenter = "submit" onclick="submit" />

我怎样才能将此卷号传递给服务器,以便我可以处理一个 HTML 页面?

如何为用户名、密码等做到这一点?

这是我到目前为止所做的,它没有产生任何结果:

Byte[] Bytes;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://xvc.com/result.php");
Stream RequestStream;
HttpWebResponse Response;

Bytes = Encoding.UTF8.GetBytes("006453");
request.Method = "POST";
request.ContentLength = Bytes.Length;
request.ContentType  = "text/Html"; //Set accordingly

RequestStream = request.GetRequestStream();
RequestStream.Write(Bytes, 0, Bytes.Length);
RequestStream.Close();

Response = ( HttpWebResponse) request.GetResponse(); 
StreamReader ResponseStream = new StreamReader(Response.GetResponseStream(), Encoding.ASCII);

字符串结果 = ResponseStream.ReadToEnd(); ResponseStream.Close(); MessageBox.Show(Result);

【问题讨论】:

  • 感觉就像你有两个问题交织在一起。 Winforms 和登录 PHP 站点与根据卷号获取考试结果有什么关系?您是否尝试使用 Winforms 应用程序连接到网页、输入信息并取回结果?
  • @BiggsTRC :确切地说,我正在尝试制作将传递卷号的应用程序,获取 resultstatus.php 然后只显示结果,而且我无法弄清楚是什么准确地说,我说:登录网站,有什么建议吗??

标签: c# winforms login httpwebrequest


【解决方案1】:

您基本上必须创建一个到 resultstatus.php 的 HTTP POST 并为其提供卷号 (regno)。

您可能希望看到this almost identical question,尤其是this article

【讨论】:

  • 哦,终于明白了。感谢您提供链接。:)
  • 抱歉 - POST 在消息正文中发送数据,而不是 GET 使用的标头。
  • 那么,如果方法是 GET,那么我应该将参数名称和值作为标头添加,而不是在 RequestStream 中??
  • 没错,GET 只能通过标头而不是请求正文发送值,这是它们的根本区别之一。
  • 谢谢你向我澄清......:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-07
  • 2016-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多