简体   繁体   中英

How to get header values from browser in Swing Application?

I have one URL lets say (www.example.com). When I hit this URL using below code it will be opened in system default browser.In the browser it will ask user to enter username and password . Then he has to enter username and password. If they are correct again the page will be redirected to (www.example.com).Now i have to get header value "isSuccess" form the browser.If it is normal web application i can achieve it using " request.getHeader("isSuccess") ". But How can I achieve the same in Swing Application?

//Swing code to open URL in default browser
Desktop d=Desktop.getDesktop();
d.browse(new URI("http://www.example.com")); 

Note : Due to security reasons I used dummy URLs above.

You can't do it using Desktop . All Desktop.browse() does is tell the default browser to open a URL. Just as if you navigated to a certain URL in your favorite browser, it doesn't display the HTTP header information for you to see.

Two options. First using a browser inside of you Swing applications, such as with this: http://djproject.sourceforge.net/ns/index.html

Second, using a custom protocol. In this case a web page, such as your success page, can send a message to an installed application. You'll have to have a different solution per platform though ( OS X JRE 6 , OS X JRE 7, look at documentation on how to add a custom protocol , Windows ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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