I am interested in logging in Java from programmatic Java to OWA (Microsoft Outlook Web Access - a web based email client) I did not get anything from the code and the inbox count - I can read this number from the HTML source of the Inbox Web page - but the problem is getting there - logging in.
Originally, seeing the HTML source of the OWA logon page, I can see that there is an HTML form element:
& lt; Form action = "owaauth.dll" method = "post" name = "logonform" autocomplete = "off" & gt; is submitted by a button element in it:
& lt; Input type = "submit" class = "btn" value = "log on" onclick = "clkLgn ()" & gt; By checking the clkLgn () script, I think this sends a cookie to the document, so it is not important:
function clkLgn () {If (gbid ("rdoprovt") checked) {var oD = new date (); OD.setTime (oD.getTime (+ 2 * 7 * 24 * 60 * 60 * 1000); Var sA = "acc =" + (gbid ("chkBsc"). 1: 0) checked; Var sL = "lgn =" + gbid ("user name") Values; Document.cookie = "logondata =" + SA + "& amp;" + SL + ", ending =" + oD.toUTCString (); }} Actually, how can I send this form? The following code is my attempt at this problem, I can make the HTTP connection - but I can not be able to post the correct HTTP request.
URL urlObject = new URL (url)); HttpURLConnection hConnection = (HttpURLConnection) urlObject.openConnection (); HttpURLConnection.setFollowRedirects (correct); HConnection.setDoOutput (true); HConnection.setRequestMethod ("Post"); PrintStream ps = new printstream (hConnection.getOutputStream ()); Ps.print ("username" = username + "& amp; password =" + password); Ps.close (); HConnection.connect (); If (HttpURLConnection.HTTP_OK == hConnection.getResponseCode ()) {InputStream = hConnection.getInputStream (); OutputStream OS = New FileOutputStream ("output.html"); Int data; While ((Data = Reid ())! = -1) {os.write (data); } is close(); Os.close (); HConnection.disconnect (); } This keeps returning the same logon HTML page. This Javascript is definitely an important thing: This document adds a cookie to a decent HTTP client:
In addition, there are several things to take into account when presenting programs as programs: You must not leave any hidden input field ( input type = "hidden" ), This relevance may also send the name = value pair of whatever you want to press programmatically as the requested parameter. Finally, you'll see the & amp; Amp; parameter should not be used to combine combinations, but & amp; .
Note that I will not guarantee it will eventually work, that OWA things may have some other prevention against bots, but it should solve the distant problems.
See also:
By the way, do you like a SMTP / IMAP API?
Comments
Post a Comment