0

我有一个网页:http: //180.92.171.80/ffs/data-flow-list-based/。从下拉菜单中填写流域名称和河流名称后,站点名称会出现在洪水预报站点中,当我选择其中任何一个时,它会自动重定向以返回该站点的信息。我显然需要使用 C# 定期保存该信息(姓名、日期和当前水位)。

我对 C# 有一些了解。我在网页发布和名称值收集上尝试了一些代码,但没有成功。

代码是:

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.yoursite.com");
request.Method = "POST";

formContent = "FormValue1=" + someValue +
    "&FormValue2=" + someValue2 +
    "&FormValue=" + someValue2;

byte[] byteArray = Encoding.UTF8.GetBytes(formContent);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = HttpUtility.UrlDecode(reader.ReadToEnd());
//You may need HttpUtility.HtmlDecode depending on the response

reader.Close();
dataStream.Close();
response.Close();

另一个代码:

WebRequest req = WebRequest.Create("http://mysite/myform.aspx");
string postData = "item1=11111&item2=22222&Item3=33333";

byte[] send = Encoding.Default.GetBytes(postData);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = send.Length;

Stream sout = req.GetRequestStream();
sout.Write(send, 0, send.Length);
sout.Flush();
sout.Close();

WebResponse res = req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
string returnvalue = sr.ReadToEnd();

任何人都可以在这方面帮助我吗?这对我会有很大的帮助。提前致谢。

4

1 回答 1

0

您还可以通过 Jquery 通过 div 或 span 值读取数据

于 2015-08-18T09:21:27.673 回答