Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2006

Tip: Looking for answers? Try searching our database.

C# Newbie

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alvis - 23 Aug 2006 19:34 GMT
Hello,
i am trying to make an Https request to a coradiant box. the box monitors
perforamnce of our website. when i paste the url into IE i am asked to accept
a ceritificate. then i get a dialog box asking where to save the file. I have
written a C# application. the will make the https request and i am stroring
the responces in a stream. but i cant read the stream i get an error the
stream does not support seek operations. here is url and  the code that i am
have written can someone tell me whats i amdoing wrong thanks

https://truesight/wpdata?usr=xxxx&pwd=xxxxx&timeframe=fullday&format=CSV&zip=false

        internal class AcceptAllCertificatePolicy : ICertificatePolicy
        {
            public AcceptAllCertificatePolicy()
            {
            }

            public bool CheckValidationResult(ServicePoint sPoint,
                X509Certificate cert, WebRequest wRequest,int certProb)
            {
                // Always accept
                return true;
            }
        }

        private void btnGetData_Click(object sender, System.EventArgs e)
        {
            try
               
               {
                ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();
                string rq =
System.Configuration.ConfigurationSettings.AppSettings.GetValues("httpReq").GetValue(0).ToString().Replace("%20","&");
               //X509Certificate Cert =
X509Certificate.CreateFromCertFile("192.168.0.199");
                X509Certificate Cert =
X509Certificate.CreateFromCertFile(@"C:\\Documents and Settings\afloyd\My
Documents\Truesight\TSDateExtractor\bin\Debug\ts.cer");
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(rq);
                //req.ClientCertificates
                req.ClientCertificates.Add(Cert);
                req.UserAgent = "Client Cert Sample";
                req.Method = "GET";
               
                HttpWebResponse Response = (HttpWebResponse)req.GetResponse();
               
                Stream ReceiveStream = Response.GetResponseStream();
           
                byte[] bytes = new byte[1000];
                int numBytesToRead = 5000;
                int numBytesRead = 500;
                while (numBytesToRead > 0)
                {
                    // Read may return anything from 0 to numBytesToRead.
                    int n = ReceiveStream.Read(bytes, numBytesRead, numBytesToRead);
                    // The end of the file is reached.
                    if (n==0)
                        break;
                    numBytesRead += n;
                    numBytesToRead -= n;
                }
               
               
               ReceiveStream.Close();

                }

            catch (System.Exception ex)
                {
                Console.WriteLine("{0} Exception caught.", ex);
                }

        }
Peter Bromberg [C# MVP] - 23 Aug 2006 21:15 GMT
Alvis,

Stream ReceiveStream = Response.GetResponseStream();

Shouldn't that be:

Stream ReceiveStream = Request.GetResponseStream();

Also, if the stream isn't very big, you should be able to read it in one go:

byte[] bytes = new byte[ReceiveStream.Length];  // or something to that
effect.

Peter

Signature

Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com

> Hello,
> i am trying to make an Https request to a coradiant box. the box monitors
[quoted text clipped - 69 lines]
>
>         }
Alvis - 23 Aug 2006 21:21 GMT
thanks peter i see the error of my ways!

> Alvis,
>
[quoted text clipped - 84 lines]
> >
> >         }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.