On Thu, May 28, 2009 at 07:25:27PM -0700, Ridwan Tan (ridtan) wrote:
> Hello,
> 
>  
> 
> I am trying to use httpclient to login to Exchange OWA with FBA
> authentication enabled. I am able to perform FBA authentication.
> Exchange kept returning an error saying that cookie is not enabled by
> the browser. I have read the primer and I have seen many posts around
> this area. I have copied some of the solution, but I can't get it to
> work somehow. I have copied the code snipet that I used as well as the
> debug output of the wire. I am just wondering if anyone encounters
> similar issue or know what's wrong with the code below. I have tried all
> the combination of CookiePolicy as well and I still get the same
> results.
> 
>  
> 
> I thank you in advance for your time.
> 
>  
> 
> Regards,
> 
>  
> 
> Ridwan
> 

Ridwan,

I _suspect_ this problem has nothing to do with the cookie policy used by
HttpClient. Apparently the site rejects the request based purely on the content
of the User-Agent header. Try  masquerading HttpClient as a browser such as IE
by using the same User-Agent string the site is known to work with.

Hope this helps

Oleg


>  
> 
>         StringBuffer sb = new StringBuffer();
> 
>         sb.append("<somehostname>");
> 
>  
> 
>         System.out.println(sb.toString());
> 
>         HttpClient http = new HttpClient();
> 
>         
> 
>         HttpConnectionParams connParams =
> http.getHttpConnectionManager().getParams();
> 
>         connParams.setConnectionTimeout(60*1000);
> 
>  
> 
>         HttpClientParams params = new HttpClientParams();
> 
>         HttpState initialState = new HttpState();
> 
>  
> 
>         // and then added to your HTTP state instance
> 
>         http.setParams(params);
> 
>         http.setState(initialState);
> 
>  
> 
>         GetMethod get = new GetMethod(sb.toString());
> 
>  
> get.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
> 
>        
> 
>         http.executeMethod(get);
> 
>         get.getResponseBodyAsString();
> 
>         get.releaseConnection();
> 
>         //post execution follow
> 
>  
> 
>  
> 
>  
> 
> 2009/05/28 19:04:21:085 PDT [DEBUG] HttpClient - Java version: 1.5.0_07
> 
> 2009/05/28 19:04:21:085 PDT [DEBUG] HttpClient - Java vendor: Sun
> Microsystems Inc.
> 
> 2009/05/28 19:04:21:085 PDT [DEBUG] HttpClient - Java class path:
> 2009/05/28 19:04:21:085 PDT [DEBUG] HttpClient - Operating system name:
> Windows XP
> 
> 2009/05/28 19:04:21:085 PDT [DEBUG] HttpClient - Operating system
> architecture: x86
> 
> 2009/05/28 19:04:21:085 PDT [DEBUG] HttpClient - Operating system
> version: 5.1
> 
> 2009/05/28 19:04:21:163 PDT [DEBUG] HttpClient - SUN 1.5: SUN (DSA
> key/parameter generation; DSA signing; SHA-1, MD5 digests; SecureRandom;
> X.509 certificates; JKS keystore; PKIX CertPathValidator; PKIX
> CertPathBuilder; LDAP, Collection CertStores)
> 
> 2009/05/28 19:04:21:163 PDT [DEBUG] HttpClient - SunRsaSign 1.5: Sun RSA
> signature provider
> 
> 2009/05/28 19:04:21:163 PDT [DEBUG] HttpClient - SunJSSE 1.5: Sun JSSE
> provider(PKCS12, SunX509 key/trust factories, SSLv3, TLSv1)
> 
> 2009/05/28 19:04:21:163 PDT [DEBUG] HttpClient - SunJCE 1.5: SunJCE
> Provider (implements RSA, DES, Triple DES, AES, Blowfish, ARCFOUR, RC2,
> PBE, Diffie-Hellman, HMAC)
> 
> 2009/05/28 19:04:21:163 PDT [DEBUG] HttpClient - SunJGSS 1.0: Sun
> (Kerberos v5)
> 
> 2009/05/28 19:04:21:163 PDT [DEBUG] HttpClient - SunSASL 1.5: Sun SASL
> provider(implements client mechanisms for: DIGEST-MD5, GSSAPI, EXTERNAL,
> PLAIN, CRAM-MD5; server mechanisms for: DIGEST-MD5, GSSAPI, CRAM-MD5)
> 
> 2009/05/28 19:04:21:163 PDT [DEBUG] DefaultHttpParams - Set parameter
> http.useragent = Jakarta Commons-HttpClient/3.1
> 
> 2009/05/28 19:04:21:163 PDT [DEBUG] DefaultHttpParams - Set parameter
> http.protocol.version = HTTP/1.1
> 
> 2009/05/28 19:04:21:163 PDT [DEBUG] DefaultHttpParams - Set parameter
> http.connection-manager.class = class
> org.apache.commons.httpclient.SimpleHttpConnectionManager
> 
> 2009/05/28 19:04:21:163 PDT [DEBUG] DefaultHttpParams - Set parameter
> http.protocol.cookie-policy = default
> 
> 2009/05/28 19:04:21:163 PDT [DEBUG] DefaultHttpParams - Set parameter
> http.protocol.element-charset = US-ASCII
> 
> 2009/05/28 19:04:21:163 PDT [DEBUG] DefaultHttpParams - Set parameter
> http.protocol.content-charset = ISO-8859-1
> 
> 2009/05/28 19:04:21:163 PDT [DEBUG] DefaultHttpParams - Set parameter
> http.method.retry-handler =
> org.apache.commons.httpclient.defaulthttpmethodretryhand...@c05d3b
> 
> 2009/05/28 19:04:21:163 PDT [DEBUG] DefaultHttpParams - Set parameter
> http.dateparser.patterns = [EEE, dd MMM yyyy HH:mm:ss zzz, EEEE,
> dd-MMM-yy HH:mm:ss zzz, EEE MMM d HH:mm:ss yyyy, EEE, dd-MMM-yyyy
> HH:mm:ss z, EEE, dd-MMM-yyyy HH-mm-ss z, EEE, dd MMM yy HH:mm:ss z, EEE
> dd-MMM-yyyy HH:mm:ss z, EEE dd MMM yyyy HH:mm:ss z, EEE dd-MMM-yyyy
> HH-mm-ss z, EEE dd-MMM-yy HH:mm:ss z, EEE dd MMM yy HH:mm:ss z,
> EEE,dd-MMM-yy HH:mm:ss z, EEE,dd-MMM-yyyy HH:mm:ss z, EEE, dd-MM-yyyy
> HH:mm:ss z]
> 
> 2009/05/28 19:04:21:178 PDT [DEBUG] DefaultHttpParams - Set parameter
> http.connection.timeout = 60000
> 
> 2009/05/28 19:04:21:210 PDT [DEBUG] DefaultHttpParams - Set parameter
> http.protocol.cookie-policy = compatibility
> 
> 2009/05/28 19:04:21:225 PDT [DEBUG] HttpConnection - Open connection to
> <hostname>
> 
> 2009/05/28 19:04:21:256 PDT [DEBUG] header - >> "GET
> /owa/auth/logon.aspx HTTP/1.1[\r][\n]"
> 
> 2009/05/28 19:04:21:256 PDT [DEBUG] HttpMethodBase - Adding Host request
> header
> 
> 2009/05/28 19:04:21:272 PDT [DEBUG] header - >> "User-Agent: Jakarta
> Commons-HttpClient/3.1[\r][\n]"
> 
> 2009/05/28 19:04:21:272 PDT [DEBUG] header - >> "Host:
> <somehostname>[\r][\n]"
> 
> 2009/05/28 19:04:21:272 PDT [DEBUG] header - >> "[\r][\n]"
> 
> 2009/05/28 19:04:21:272 PDT [DEBUG] header - << "HTTP/1.1 200
> OK[\r][\n]"
> 
> 2009/05/28 19:04:21:272 PDT [DEBUG] header - << "HTTP/1.1 200
> OK[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] header - << "Cache-Control:
> no-cache[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] header - << "Pragma:
> no-cache[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] header - << "Content-Length:
> 8346[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] header - << "Content-Type:
> text/html; charset=utf-8[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] header - << "Expires: -1[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] header - << "Server:
> Microsoft-IIS/6.0[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] header - << "X-Powered-By:
> ASP.NET[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] header - << "X-AspNet-Version:
> 2.0.50727[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] header - << "X-OWA-Version:
> 8.1.240.5[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] header - << "Date: Fri, 29 May 2009
> 02:03:58 GMT[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] header - << "[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] HttpMethodBase - Buffering response
> body
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] content - << "<!-- Copyright (c)
> 2006 Microsoft Corporation.  All rights reserved. -->[\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] content - << "<!-- OwaPage =
> ASP.auth_logon_aspx -->[\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] content - << "[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] content - << "<!--
> {57A118C6-2DA9-419d-BE9A-F92B0F9A418B} --> [\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] content - << "[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] content - << "<!DOCTYPE HTML PUBLIC
> "-//W3C//DTD HTML 4.0 Transitional//EN"> [\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] content - << "<html>[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] content - << "<head>[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] content - << "<meta
> http-equiv="Content-Type" content="text/html; CHARSET=utf-8">[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] content - << "<meta name="Robots"
> content="NOINDEX, NOFOLLOW">[\r][\n]"
> 
> 2009/05/28 19:04:21:288 PDT [DEBUG] content - << "<title>Microsoft
> Exchange - Outlook Web Access</title>[\r][\n]"
> 
> ... //the login page
> 
> 009/05/28 19:04:21:303 PDT [DEBUG] content - <<
> "[0x9][0x9][0x9][0x9][0x9]<td><br>Please enable cookies for this web
> site.<br><br>Cookies are currently disabled by your browser. Outlook Web
> Access requires that cookies be enabled. <br><br>If you are using
> Microsoft Internet Explorer 6 or later, open Internet Options from the
> Tools menu. Click the Privacy tab, and then click Sites. Type the
> address for Outlook Web Access into the field, click Allow, and then
> click OK to save your changes.<br><br><br></td>[\r][\n]"
> 
> 2009/05/28 19:04:21:303 PDT [DEBUG] content - <<
> "[0x9][0x9][0x9][0x9]</tr>[\r][\n]"
> 
> 2009/05/28 19:04:21:303 PDT [DEBUG] content - <<
> "[0x9][0x9][0x9][0x9]<tr><td><hr></td></tr>[\r][\n]"
> 
> 2009/05/28 19:04:21:303 PDT [DEBUG] content - <<
> "[0x9][0x9][0x9][0x9]<tr>[\r][\n]"
> 
> 2009/05/28 19:04:21:303 PDT [DEBUG] content - <<
> "[0x9][0x9][0x9][0x9][0x9]<td align="right" class="txtpad">[\r][\n]"
> 
> 2009/05/28 19:04:21:303 PDT [DEBUG] content - <<
> "[0x9][0x9][0x9][0x9][0x9][\r][\n]"
> 
> 2009/05/28 19:04:21:303 PDT [DEBUG] content - <<
> "[0x9][0x9][0x9][0x9][0x9][0x9]<input type="button" class="btn"
> style="float: right" value="Retry" onclick="clkRtry()">[\r][\n]"
> 
> 2009/05/28 19:04:21:303 PDT [DEBUG] content - <<
> "[0x9][0x9][0x9][0x9][0x9][\r][\n]"
> 
> 2009/05/28 19:04:21:303 PDT [DEBUG] content - <<
> "[0x9][0x9][0x9][0x9][0x9]</td>[\r][\n]"
> 
> ...
> 
> 009/05/28 19:04:21:303 PDT [DEBUG] content - << "</table>[\r][\n]"
> 
> 2009/05/28 19:04:21:303 PDT [DEBUG] content - << "</form>[\r][\n]"
> 
> 2009/05/28 19:04:21:303 PDT [DEBUG] content - << "[\r][\n]"
> 
> 2009/05/28 19:04:21:303 PDT [DEBUG] content - << "</body>[\r][\n]"
> 
> 2009/05/28 19:04:21:303 PDT [DEBUG] content - << "</html>[\r][\n]"
> 
> 2009/05/28 19:04:21:303 PDT [DEBUG] HttpMethodBase - Resorting to
> protocol version default close connection policy
> 
> 2009/05/28 19:04:21:303 PDT [DEBUG] HttpMethodBase - Should NOT close
> connection, using HTTP/1.1
> 
> 2009/05/28 19:04:21:303 PDT [DEBUG] HttpConnection - Releasing
> connection back to connection manager.
> 
>  
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to