开发者

set cookie in java

开发者 https://www.devze.com 2023-01-27 16:45 出处:网络
I am developing a web browser in java . To parse the HTML page into a DOM document then to render it I use an API\"cobra\" . But

I am developing a web browser in java . To parse the HTML page into a DOM document then to render it I use an API "cobra" . But it is not cookie enabled . So I have to manage it by myself. I create a class that can collect cookie from web-page . That is not my problem. But the problem is that when 开发者_如何学CI click in log-in button of a website that need cookie to log-in like facebook (because log-in button is a java-script button so my browser has to implement the java-script function .But that API can also handle java-script function) as an event of button clicking the API internally create a connection to server and send the data. But I need to create that connection to the server for setting cookie. Because the API internally create the URL-Connection ( The API has no method to set property to URL-Connection ) .So how can I send cookie with URL-connection . If you have any better idea that can solve my crisis plz share with me.


You've not posted any code that makes a request, but I think what you need to do is this:

URLConnection conn = you get a connection from somewhere...;
...
conn.setRequestProperty("Cookie", "cookieName=cookieValue");
...

See here for more details, Also you may want to research cookies a bit to make sure your implementation is secure and works.

Also, remember that javascript is allowed access to cookies through document.cookie.

0

精彩评论

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