[Mono-bugs] [Bug 73275][Nor] New - Network code fails with Mono, but works with .Net

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 3 Mar 2005 07:19:00 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by r_holmes@yahoo.com.

http://bugzilla.ximian.com/show_bug.cgi?id=73275

--- shadow/73275	2005-03-03 07:19:00.000000000 -0500
+++ shadow/73275.tmp.17615	2005-03-03 07:19:00.000000000 -0500
@@ -0,0 +1,222 @@
+Bug#: 73275
+Product: Mono: Class Libraries
+Version: 1.0
+OS: 
+OS Details: Debian unstable packages of Mono
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Sys.Web
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: r_holmes@yahoo.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Network code fails with Mono, but works with .Net
+
+I'm writing a simple application in C# that logs into a Yahoo Mail account
+by simulating a browser. 
+
+During the login process, it is redirected (through the http header)
+through a number of servers until it finally reaches the inbox, if
+successful. To each server it sends the cookies received so far.
+
+However, I can't get the login process to work with Mono (1.0.5, Debian 
+unstable). With .Net-runtime on Windows, it works perfectly.
+
+If we look at the Trace-output running the application on Windows, it 
+reaches my inbox at step 14:
+
+1: Logging into Yahoo Mail with username 'r_holmes' and password 'xxxx'
+2: Opening 
+'http://mail.yahoo.com/config/login?.intl=us&.us=ym&.tries=1&.src=ym&login=r_holmes&passwd=xxxx'
+3: UpdateCookieCollection()
+4: No previous cookies stored. Store all cookies
+5:    B 4fuqucl12920k&b=2
+6:    F a=J06ons0sva8HnAxcQd0gGflizzgSbIkvrjqtKkO_UelR1SmfYg.SzWz1NeVd&b=_DjV
+7:    Y v=1&n=frfgoo6e3klnv&l=h_7ebc4i/o&p=m2evvdk013000000&jb=16|23|
+3&ig=0f1kb&iz=5932&r=2d&lg=us&intl=us&np=1
+8:    T 
+z=UgIJCBUmdJCBBifXWTwKl.iMjMxBjYzMTYxNE8xNw--&a=QAE&sk=DAAhBq4AhwE.1m&d=c2wBTlRRMkFURTBOakUyTXpnMk1BLS0BYQFRQUUBaWcBVjNTVEJBAXRpcAFRZEtfaEQBenoBVWdJSkNCZ1dB
+9: Redirecting to 
+'http://login.yahoo.com/config/verify?.done=http%3a//us.f546.mail.yahoo.com/ym/login%3f.rand=01gj9h49dpaih'
+10: Setting up cookies to sent with the request
+11: Opening 
+'http://login.yahoo.com/config/verify?.done=http://us.f546.mail.yahoo.com/ym/login?.rand=01gj9h49dpaih'
+12: Redirecting to 
+'http://us.f546.mail.yahoo.com/ym/login?.rand=01gj9h49dpaih'
+13: Setting up cookies to sent with the request
+14: Opening 'http://us.f546.mail.yahoo.com/ym/login?.rand=01gj9h49dpaih'
+15: UpdateCookieCollection()
+16:    Adding new key/value pair: 
+'YM.Gen'/'i=vaJ46Ur8iCyUC6SohqziJVP0lrSkYKjdTmsYzl0doCY2i3KytxJ_HAyp6w7V.c98W1bFLdoH8iGPyhITUWD1wuAX_q2.1hYj4gEQ38OFhLh1mTwwK.Ylm.ZmUV_NPIyjjO74ehM_uuYUTNPQFWkpvNbMNte.Bfd98jAMYAjUbQYm_kFVlNAESrPdnINBKBULD1_zSe0.Q7OE.iI5WGhXBrrYlo0GN44ZcwK3t1v0P_5Ryl1MSiuxuzuFvByz1R4YQ0EJ3Y_BrJHAH6Jom0LbcdtPnstLOHShR6_bgAp_WHGZM8Aa8uMALYZNO7_t5ziChZD5eDy9EPEZMC725W_KIGJfyjmyRRaAwm_z5oWl3vTcyo7dM8K2OiHOmq7jybrbqK92bEJMQw1yhoywCa2i1725CWTyRF6FEvyQLcH3ETmOG7oIVStFQ5hhRvmW5bToznLdm62ddmz1Cg9o5p_7mT5Mwh18M78Ve9Gl3trJUSHknsKYTmsWNgb2WhOOuhDvChQ_X7IP4rek_vXhJ6QNyyAhGSzN5XuxP1pYZeFfH7VjXaSENOOsdagnyPE3Stvz.5JDWsigL.SHgCPdFprBCl7GWertr02iLBBic_0nd3NL8fGDlicXxz6MM4uyhtUolJKWg_BcQL_u.Axc3R190_njne4Ty4OdiH3JdxcHqqc8YMUxcHvz_jGjZ8v3qW5mmoJs.hguE9Fl4bi5cVvPfqtPOFATXLPqCH8Ue4_MK1pH9Bdg2D3Lj35qRTujPib_rqtTUKyb_tsDb6yGKwTO_ZxzI1WjG39j3cCNMSdVn4Dl7JRsl3cxUD.KQIwNuatBxiARtIx31gBPOKXSqO_iOW1Ki9H.E8gCckwQQl6zkPBxibd_FNslukBXiSiGa7BW66r_d7LEYeoiEtxsF7gWmmB_4GiU3eCThkTNmWFpJ4Pm430kDC_Q5j3gtPsOdeBDJbfiL0ILhC060d0mw
 P6bAbqBKv1n_go7OM0E9EeErxQhNv7W0S6T5NyphbU40AJ5sJkjvNi8yk9Kaq3rrRBnGjq2uPsrFzhXAE1rdWMZWbScjWTD1hdcsayzVL7jMifCzE3cnGLpSkMcdKHMQPvLd2dX9SVQlhV2u.zHmBECpiRUYT6WGpMBzvfAML7SFt0BCHztoHyHxeLeoPvFKiurzTPe3eroy.SQtvR0lsJ4e4k30dxqWFYxuHJ2dblV3YJLnnW5v4l7xcKEIDFe0Y.WsVEH9PmA_Ojw4BCi8BI17IDNCG_lZ40XEu557ihM94z9biQg8XkhkjGtjNw9ys9T1heRI50L9K8OoODxxdyCFPYa1n4i51oiymPpTicfMZ5vGHvC8pr5PLN8qEQJ5aWo0zCKRIcESW..8cCi815aZL9QHCB70GYMusTEJtykLLkIaIVxnBtkpSiOEfQYQJbZd1wu.SP.qNQ-&v=1'
+
+And then running the application on linux:
+
+1: Logging into Yahoo Mail with username 'r_holmes' and password 'xxxx'
+2: Opening 
+'http://mail.yahoo.com/config/login?.intl=us&.us=ym&.tries=1&.src=ym&login=r_holmes&passwd=xxxx'
+3: UpdateCookieCollection()
+4: No previous cookies stored. Store all cookies
+5:    B 18dft0h12937r&b=2
+6:    F a=J06ons0sva8HnAxcQd0gGflizzgSbIkvrjqtKkO_UelR1SmfYg.SzWz1NeVd&b=_DjV
+7:    Y v=1&n=frfgoo6e3klnv&l=h_7ebc4i/o&p=m2evvdk013000000&jb=16|23|
+3&ig=0f1kb&iz=5932&r=2d&lg=us&intl=us&np=1
+8:    T 
+z=7zIJCB75dJCBIjtUO2esw7qMjMxBjYzMTYxNE8xNw--&a=QAE&sk=DAA.qR.7d3F3JI&d=c2wBTlRRMkFURTBOakUyTXpnMk1BLS0BYQFRQUUBaWcBVjNTVEJBAXRpcAFRZEtfaEQBenoBN3pJSkNCZ1dB
+9: Redirecting to 
+'http://login.yahoo.com/config/verify?.done=http%3a//us.f546.mail.yahoo.com/ym/login%3f.rand=8eb8bof6cj070'
+10: Setting up cookies to sent with the request
+11: Opening 
+'http://login.yahoo.com/config/verify?.done=http://us.f546.mail.yahoo.com/ym/login?.rand=8eb8bof6cj070'
+
+Step 11 sends me back to the login page instead of to my inbox. The Yahoo 
+error message viewing the URL of step 11 is "The browser you're using
+refuses to sign in. (cookies rejected)". I'm not sure this really is a
+cookie problem, though.
+
+I've inspected what is actually going on with Ethereal. As a response to 
+opening the URL of step 9 of the linux output, the Yahoo server responds 
+with:
+
+HTTP/1.1 200 OK[Unreassembled Packet]
+
+On Windows, the response is:
+
+HTTP/1.1 302 Found (text/html)
+
+I've attached a stripped down version of my application. Remember to
+compile it with /d:TRACE.
+
+Additional Information:
+
+using System;
+using System.IO;
+using System.Diagnostics;
+using System.Net;
+using System.Text;
+using System.Web;
+
+class YahooDrive {
+        public static void Main() {
+                Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
+                Trace.AutoFlush = true; 
+        
+                YahooMail ym = new YahooMail();
+                ym.Login("r_holmes", "xxxx"); 
+        }
+}
+
+class YahooMail {
+        CookieCollection m_cookies;
+        
+        static string m_httpLogin =
+"http://mail.yahoo.com/config/login?.intl=us&.us=ym&.tries=1&.src=ym";
+
+        public YahooMail() { }
+
+        public void Login(string aUsername, string aPassword) {
+                Debug.Assert(aUsername != "" && aPassword != "");
+
+                string urlAppend = "&login=" + aUsername +
+                                                   "&passwd=" + aPassword;
+                
+                Trace.WriteLine("Logging into Yahoo Mail with username '" +
+aUsername + "' and password '" + aPassword + "'");
+                RedirectHandler(new Uri(m_httpLogin + urlAppend));
+        }
+        
+        private void RedirectHandler(Uri aUri) {
+                Encoding enc = System.Text.Encoding.GetEncoding("utf-8");
+
+                HttpWebRequest request =
+(HttpWebRequest)WebRequest.Create(aUri);
+                request.CookieContainer = new CookieContainer();
+                                
+                if (m_cookies != null && m_cookies.Count > 0) {
+                        Trace.WriteLine("Setting up cookies to sent with
+the request");
+                        request.CookieContainer.Add(m_cookies);
+                }
+
+                SetHeaders(request);
+
+                Trace.WriteLine("Opening '" + aUri + "'");              
+                HttpWebResponse response =
+(HttpWebResponse)request.GetResponse();
+
+                if (response.Cookies.Count > 0)
+                        UpdateCookieCollection(response.Cookies);         
+     
+                
+                //StreamReader responseStream = new
+StreamReader(response.GetResponseStream(), enc);    
+                //Console.WriteLine(responseStream.ReadToEnd());
+
+                if ( (response.StatusCode == HttpStatusCode.Redirect) ||
+                         (response.StatusCode == HttpStatusCode.Found) ||
+                         (response.StatusCode == HttpStatusCode.Moved) ||
+                         (response.StatusCode ==
+HttpStatusCode.MovedPermanently) ) {
+                        Trace.WriteLine("Redirecting to '" +
+response.Headers["Location"] + "'");
+                        RedirectHandler(new Uri(response.Headers["Location"]));
+                } 
+                
+        response.Close();
+        }
+        
+        private void SetHeaders(HttpWebRequest aRequest) {
+                Debug.Assert(aRequest != null);
+
+                aRequest.Method = "GET";
+                aRequest.UserAgent = "Mozilla/5.0 (X11; U; Linux i686;
+en-US; rv:0.9.4) Gecko/20010914";
+                aRequest.AllowAutoRedirect = false;
+        }
+        
+        private void UpdateCookieCollection(CookieCollection
+responseCollection) {
+                Trace.WriteLine("UpdateCookieCollection()");
+                
+                if (m_cookies == null) {
+                        Trace.WriteLine("No previous cookies stored. Store
+all cookies");                       
+                        m_cookies = responseCollection;
+                        Trace.Indent();
+                        
+                        foreach (Cookie c in m_cookies) {
+                                Trace.WriteLine(c.Name + " " + c.Value);
+                        }
+
+                        Trace.Unindent();                       
+                }
+                else {
+                        Trace.Indent();
+
+                        foreach (Cookie responseCookie in responseCollection) {
+                                bool match = false;
+                                
+                                foreach (Cookie storedCookie in m_cookies) {
+                                        if
+(storedCookie.Name.Equals(responseCookie.Name)) {
+                                                storedCookie.Value =
+responseCookie.Value;
+                                                Trace.WriteLine("Updated
+key/value pair: '" + storedCookie.Name + "'/'" + storedCookie.Value + "'");
+                                                match = true;
+                                        }
+                                }
+                                                        
+                                if (!match)
+                                        Trace.WriteLine("Adding new
+key/value pair: '" + responseCookie.Name + "'/'" + responseCookie.Value + "'");
+                                        m_cookies.Add(responseCookie);
+                        }
+                        
+                        Trace.Unindent();               
+                }
+        }
+}