开发者

Capture or redirect open browser window event from a Java program

开发者 https://www.devze.com 2022-12-20 22:30 出处:网络
I have a Java program, that opens a new browser window when I click on on a menu. The Java program requires login, so the h开发者_运维技巧tml page has a Session ID.

I have a Java program, that opens a new browser window when I click on on a menu. The Java program requires login, so the h开发者_运维技巧tml page has a Session ID.

I want to access this page with my C# program, so that I can extract some data from it. Unfortunately, the only way to get to this html page is through the Java client's menu, so there's no way to log in in a html form.

I'd like to get the source of this html page automatically, so I thought about somehow redirecting the event that opens a new browser window if the link starts like my required page.

Another option is to change the default browser to my program before clicking the menu programmatically, and restore the original default browser afterwards.

I know that these ideas may be quite ugly, and there may be much simpler solutions, but I'm a beginner in C#, and I've never done anything like this, so I'd really appreciate any help on how to solve this problem.

Thanks in advance.


Java isn't using black magic to open the browser window. Most certainly, it just takes the url and "executes" it or it uses the desktop API. In either case, the Java program just uses HTTP protocol and you can do the same in C#.

So instead of trying to hack the OS, install a proxy which allows you to see the HTTP headers and then run the Java program once to figure out what it does. Try http://www.privoxy.org/ which is pretty easy to set up.

Then use the standard HTTP library of C# to do the same.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号