C#:如何使 HttpWebRequest 模仿 Web 浏览器控件

发布于 2024-12-19 04:51:24 字数 296 浏览 0 评论 0原文

我过去使用过多个 HttpWebRequest,但它们都被用来登录网站。

我想知道如何使 WebRequest 模仿 WebBrowser ,就像您登录后导航到新页面,也许在那里执行一项操作,然后转到不同的页面?

我之前对此进行过一些研究,我认为这可能涉及使用先前请求的 cookie 或其他东西。

我的问题是我(我假设)如何从上一个会话中获取 cookie,然后导航到一个页面,或者完成一个操作,就好像我们仍在处理最后一个请求一样,如果这有意义的话。

I've used several HttpWebRequest's in the past but they've all been used to login into a site.

I was wondering how does one make the WebRequest mimic a WebBrowser as in once you're logged in, navigate to a new page, maybe perform an action there, then go to a different page?

I've researched a little about this before and I think it might involve using the prior request's cookies or something.

My question is how do I (I'm assuming) get the cookies from the previous session, then navigate to a page, or complete an action as if we were still on the last request if that makes sense.

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

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

发布评论

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

评论(1

笑,眼淚并存 2024-12-26 04:51:24

HttpWebRequest 有一个 Cookies 属性,HttpWebResponse 有一个 CookieContainer 属性。

您记录容器中的 cookie,并将它们添加到下一个请求中。

您可能还需要在请求对象上设置 HTTP referrer 标头字段。

编辑:
这仍然不会让你模仿网络浏览器。像 JavaScript 这样的东西将无法工作/运行。并且你不会有 DOM 可以操作。

the HttpWebRequest has a Cookies property and HttpWebResponse has a CookieContainer property.

you record the cookies from the container, and add them to the next request.

you may also need to set the HTTP referrer header field on the request object.

EDIT :
this will still not get you mimicking a web browser. things like JavaScript will not work/run. and you won't have a DOM to work against.

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