从 WinForm 将参数(例如换页)传递到网站(C#)

发布于 2024-11-10 06:24:23 字数 1435 浏览 1 评论 0原文

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

我知道我必须使用 httpwebrequest 或听起来类似的东西。

这是 result.php 页面的源页面片段

<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);

string Result = ResponseStream.ReadToEnd(); ResponseStream.Close(); MessageBox.Show(结果);

I'm on my journey of learning C#. I was trying to create an app to get exam results by asking the user to enter his roll number.

I know I have to use httpwebrequest or something sounding similar.

Here is the source page snippet of the result.php page

<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" />

How can I pass this roll no to the server, so that I can have an HTML page to work upon?

How can this be done for a username, password, etc?

this is what i hv done till now and it produces no result :

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);

string Result = ResponseStream.ReadToEnd();
ResponseStream.Close();
MessageBox.Show(Result);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏尔 2024-11-17 06:24:23

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

您可能想看到这个几乎相同的问题,特别是本文

You basically have to create a HTTP POST to resultstatus.php and provide it with the roll no (regno).

You'll probably want to see this almost identical question and in particular this article.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文