开发者

Account Login Action using Java

I've been working on a simulate login action to a website using java.

Firstly I post my login information, then I get the cookies(sessionID), At开发者_StackOverflow社区 last I get the content of the website with the cookie I've got.

Now I've successfully got the cookie, but having a problem using it. The cookie contains 3 fields, sessionID, path and domain.

mainURL = new URL("login url");
HttpURLConnection connection = (HttpURLConnection) mainURL.openConnection();
connection.setRequestProperty("Cookie", sessionID);
connection.getInputStream();

I'm sure the URL I'm using matches the cookie.domain and cookie.path.

I've already try using both cookie and sessionID, and using method connection.connect(); and connection.getInputStream(); none of them worked.

Hope somebody teach me how to fix this. Thanks very much.

Edit: Thanks for your answer. But rather knowing how to accomplish the desire function, I prefer knowing what's wrong about my method while others using the alike method could success.


As an alternative you may consider using httpclient or htmlunit , which provide rich set of feature than plain HttpURLConnection

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜