简体   繁体   English

Windows.Forms.WebBrowser和重定向?

[英]Windows.Forms.WebBrowser and redirects?

I've been working on a small console application (c#) for fetching a series of csv files. 我一直在研究用于提取一系列csv文件的小型控制台应用程序(c#)。 I have an URL and some POST data and I'm using the WebBrowser component due to javascript embedded in some of the pages. 我有一个URL和一些POST数据,由于某些页面中嵌入了JavaScript,因此我正在使用WebBrowser组件。 I've run into a little problem (been debugging for 2 days now) where the webbrowser control does not redirect as specified by one of the responses (302). 我遇到了一个小问题(现在调试了2天),其中webbrowser控件未按照响应之一的指定进行重定向(302)。 See screen shot (request in red box, should redirect but doesn't): 查看屏幕截图(红色框中的请求,应重定向但不重定向): 在此处输入图片说明 Since the last request being sent is a POST with a bunch of data created by javascript and it doesn't seem to be possible to extract the post data from the webbrowser, I cannot intercept the request and just use HttpWebRequest instead. 由于发送的最后一个请求是POST,其中包含由javascript创建的一堆数据,而且似乎无法从Web浏览器中提取帖子数据,因此我无法拦截该请求,而只能使用HttpWebRequest。 I have also tried looking at other web browser components such as GeckoFX and WebKit.net, but none seem to work. 我也尝试过查看其他Web浏览器组件,例如GeckoFX和WebKit.net,但似乎没有一个起作用。 I could really use some input here, since I'm pretty much stuck. 我真的可以在这里使用一些输入,因为我几乎陷入了困境。

***Update: Added new image to point to request not redirecting correctly. ***更新:添加了新图像以指向请求未正确重定向。 Request nr. 要求 8 (wrong scenario) is the same as request nr. 8(错误方案)与请求nr相同。 6 (right scenario) 6(正确的方案)

Found the error - page was not finished loading. 发现错误-页面未完成加载。 However the WebBrowser control still doesn't fire the Navigating and Navigated events when executing a 302 redirect. 但是,当执行302重定向时,WebBrowser控件仍然不会触发Navigating和Navigated事件。

Used the HttpWebRequest object instead, since it lets you disable automatical redirecting. 改用HttpWebRequest对象,因为它使您可以禁用自动重定向。 Works perfectly. 完美运作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM