use*_*901 13 c# httpwebrequest
我需要使用HttpWebRequest来自我的应用程序(桌面)的对象将一些数据"发布"到外部网站,
并通过HttpWebResponse对象将响应返回到我的应用程序中.但是,发布数据的网页上有包含动态名称的文本框.
如何获取这些文本框的名称并发布数据HttpWebResquest?
例如,当我加载页面时,文本框名称是这样的U2FsdGVkX183MTQyNzE0MrhLOmUpqd3eL60xF19RmCwLlSiG5nC1H6wvtBDhjI3uM1krX_B8Fwc,但当我刷新页面名称更改为此U2FsdGVkX182MjMwNjIzMPAtotst_q9PP9TETomXB453Mq3M3ZY5HQt70ZeyxbRb118Y8GQbgP8.
谢谢你的任何建议.
Dar*_*rov 30
var request = WebRequest.Create("http://foo");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
using (var writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write("field=value");
}
Run Code Online (Sandbox Code Playgroud)
您可以通过XPath来识别这些名称,例如用户喜欢:
byte[] data = new ASCIIEncoding().GetBytes("textBoxName1=blabla");
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost/myservlet");
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.ContentLength = data.Length;
Stream myStream = httpWebRequest.GetRequestStream();
myStream.Write(data,0,data.Length);
myStream.Close();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
43550 次 |
| 最近记录: |