从 WinForm 将参数(例如换页)传递到网站(C#)
我正在学习 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您基本上必须创建一个到
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.