Note that there are some explanatory texts on larger screens.

plurals
  1. POSending an OWA logon form from Java
    primarykey
    data
    text
    <p>I am interested in a way to programmatically log into OWA (Microsoft Outlook Web Access - a web-based email client) from Java code and retrieve nothing more than the inbox unread count -- I can read this number from the inbox web page's HTML source - but the problem is getting there - logging in.</p> <p>Essentially, from looking at the HTML source of the OWA logon page, I can see that there is an HTML form element:</p> <pre><code>&lt;form action="owaauth.dll" method="POST" name="logonForm" autocomplete="off"&gt; </code></pre> <p>that gets submitted by a button element within it:</p> <pre><code>&lt;input type="submit" class="btn" value="Log On" onclick="clkLgn()"&gt; </code></pre> <p>From investigating the clkLgn() script, I find that it sends a cookie to the document so it may not be crucial:</p> <pre><code>function clkLgn() { if(gbid("rdoPrvt").checked) { var oD=new Date(); oD.setTime(oD.getTime()+2*7*24*60*60*1000); var sA="acc="+(gbid("chkBsc").checked?1:0); var sL="lgn="+gbid("username").value; document.cookie="logondata="+sA+"&amp;"+sL+";expires="+oD.toUTCString(); } } </code></pre> <p>Basically, how can I send this form? The following code is my attempt at the problem, I can make the HTTP connection - but I can't seem to be able to POST the correct HTTP request.</p> <pre><code> URL urlObject = new URL(url); HttpURLConnection hConnection = (HttpURLConnection)urlObject.openConnection(); HttpURLConnection.setFollowRedirects(true); hConnection.setDoOutput(true); hConnection.setRequestMethod("POST"); PrintStream ps = new PrintStream(hConnection.getOutputStream()); ps.print("username="+username+"&amp;amp;password="+password); ps.close(); hConnection.connect(); if( HttpURLConnection.HTTP_OK == hConnection.getResponseCode() ) { InputStream is = hConnection.getInputStream(); OutputStream os = new FileOutputStream("output.html"); int data; while((data=is.read()) != -1) { os.write(data); } is.close(); os.close(); hConnection.disconnect(); } </code></pre> <p>It just keeps returning the same logon HTML page.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload