zidan Posted October 29, 2007 Posted October 29, 2007 Hello Mindenki! Nem tudom ki fogja tudni ezt megválaszolni, de aki megteszi annak respect. Szeretnék C# alatt https kapcsolatot megvalósítani Localhost-on. Sajna nem megy. Web Developer Center -t töltöttem le mivel az Apache-on nincs ilyen és nem tudom bekonfigozni. Webböngészõbõl megy, de már C#-al már nem. A kód: // Creates an HttpWebRequest for the specified URL. HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("https://192.168.4.140/"); X509Store store = new X509Store("My", StoreLocation.CurrentUser); // Create a new HttpWebRequest Object to the mentioned URL. myHttpWebRequest.MaximumAutomaticRedirections=1; myHttpWebRequest.AllowAutoRedirect = true; myHttpWebRequest.Credentials = CredentialCache.DefaultCredentials; myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)"; myHttpWebRequest.KeepAlive = true; myHttpWebRequest.Headers.Set("authorization", "no-cache"); myHttpWebRequest.Timeout = 300000; myHttpWebRequest.Method = "GET"; myHttpWebRequest.ContentType = ""; myHttpWebRequest.PreAuthenticate = false; try { // Sends the HttpWebRequest and waits for response. HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); // Displays each header and it's key associated with the response. //for(int i=0; i < myHttpWebResponse.Headers.Count; ++i) //Console.WriteLine("\nHeader Name:{0}, Value :{1}",myHttpWebResponse.Headers.Keys,myHttpWebResponse.Headers); // Set 'Preauthenticate' property to true. Credentials will be sent with the request. try { StreamReader sr = new StreamReader(myHttpWebResponse.GetResponseStream()); string elem = sr.ReadToEnd(); MessageBox.Show(elem); } catch (IOException el) { MessageBox.Show(el.Message, "IOException>>download"); } } catch (WebException el) { MessageBox.Show(el.Message, "WebException>>download"); //Console.WriteLine(el); } } Hibát dob: A kapcsolat bel lett zárva, nem sikerült létrehozni a bizalmi elemeket a biztonságos kapcsolat az SSL/TLS része. Elõre is köszi a segítséget. Zidan
artur02 Posted November 14, 2007 Posted November 14, 2007 Próbáld meg a KeepAlive sort false-ra állítani. Talán segít.
zidan Posted November 22, 2007 Author Posted November 22, 2007 Gond megoldva! Ha valakit érdekel akkor az alábbi kód mûködik. public void connTohttps() { try { System.Net.ServicePointManager.CertificatePolicy = new MyPolicy(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://gmail.com/"); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (Stream dataStream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(dataStream)) { string data = reader.ReadToEnd(); Console.WriteLine(data); MessageBox.Show(data); } } } } catch (Exception e) { Console.WriteLine(e.ToString()); MessageBox.Show(e.ToString(), "Exception"); } } public class MyPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint , X509Certificate certificate , WebRequest request , int certificateProblem) { //Return True to force the certificate to be accepted. return true; } // end CheckValidationResult } // class MyPolicy Addig nem ment tovább amíg certificate-ra nem bóítottunk rá. Mert a firefox azt csinálja hogy mikor letölti az oldalat akkor nyit közben egy másik kapcsolatot és letölti a certicicate-et és ezt összehasonlítja és ha a kettõ egyezzik akkor tovább engedi a kapcsolatot. Na ée ezt az igazság értéket kellett nekem beállítani. Ennyi. Remélem valakinek segítettem. Magamnak igen.
artur02 Posted November 22, 2007 Posted November 22, 2007 Hát ez trükkös. Köszi, hogy megosztottad velünk!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now