开发者

Java / .NET spawn browser with cookie set

I can spawn a browser from my Java thick client using java.awt.Desktop.

Apprarently, I can also spawn a browser from my .NET client using System.Diagnostics.Process.Start

My question is, is there a way in both Java / .NET to set a cookie when spawning the browser process? It doesn't lo开发者_如何学Gook like there is - possibly due to security concerns?


There is not. You could probably add some sort of plugin in the target browser, but that would be with a different mechanism.

What java.awt.Desktop does , it just launch the browser. There is no more interaction with it.


What I ended up doing was to spawn an intermediate page like:

Desktop.getDesktop().browse(
    new URI("http://localhost/intermediate.html?mytoken=bar")
);

Then have a bit of JavaScript to take the request param, set it as a cookie, and then forward onto the destination page.

var query = location.search;
var tokenRe = /mytoken=([^?]*)/;
var token = query.match(tokenRe)[1];
document.cookie = 'MYTOKEN=' + token
location.replace('http://localhost/destination')

Simples!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜