编程$在Web页p $ pssing按钮按钮、Web、pssing

2023-09-06 00:00:01 作者:有人疼才显得出众

目前在我们的内网网页驻留在的http://server1/rsyncwebgui.php 这对我们提供了一种快速的方法来触发rsync的两种​​文件共享之间。对于无趣的安全考虑,这是我们必须采取的路径。

There is a webpage on our intranet which resides at http://server1/rsyncwebgui.php which provides a quick way for us to trigger an rSync between two file shares. For uninteresting security reasons, this is the route we have to take.

该网页看起来是这样的:

The web page looks like this:

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
  <title>Rsync web gui</title>
</head>
<body>
  <script language="javascript">
    window.onload = function () { setTimeout(submitForm, 10000); }
    function submitForm() { document.getElementById('myform').submit(); }
  </script>
<h3> Execute rsync between server2 and server3</h3>
<form id="myform" method="POST">
  <input type="hidden" name="resync" value="false">
  <input type="hidden" name="scanscheduled" value="false">
  <input type="submit" value="Start sync">
</form>
<p>
  <script language="javascript">
    window.onload = function () {
      if (confirm('Are you sure to start the sync?')) {
  var formobj = document.getElementById('myform');
  formobj.elements['resync'].value = 'true';
  formobj.submit();
      }
    }
  </script>
</p>
<p><a href="/rsyncwebgui.php">Refresh page</a></p>

</body></html>

当用户点击该按钮,一个确定/取消对话框弹出,要求他们确认。当行被点击,页面回和rsync的被触发。

When a user clicks on the button, an "OK/Cancel" dialog pops up asking them to confirm. When OK is clicked, the page posts back and the rsync is triggered.

我如何开车从远程,C#控制台应用程序这种互动?

How would I drive this interaction from a remote, C# console application?

推荐答案

无法检查在VS了,但你会像这样结束:

Can't check in VS now, but you will end with something like this :

string postDataStr = string.Format("resync=true&scanscheduled=&otherpara=xyz");
byte[] postData = Encoding.ASCII.GetBytes(postDataStr);

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri("http://server1/rsyncwebgui.php"));
req.Method= "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = postData.Length;
using(var reqStream = req.GetRequestStream())
{
    reqStream.Write(postData, 0, postData.Length);
}

HttpWebResponse response = (HttpWebResponse )req.GetResponse();