Upload/Download a File on HTTPS site in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wolfenstein
    New Member
    • Mar 2008
    • 25

    Upload/Download a File on HTTPS site in C#

    Hi,
    I'm searching for this solution from a long time now. i have a https protocol site from a client and i need to upload and download some files from my window service.
    Now this site also requires a Client Certificate that i have already imported in my browser and through the browser i can easily access its folders.

    Can anyone please tell me how can i make this possible using C# in my window service? I'm looking for its resolution very desperately.
    Thanks!
  • wolfenstein
    New Member
    • Mar 2008
    • 25

    #2
    Its really strange that i'm googling the web and found many occurrences about this issue but NO RESOLUTION?
    Is there anyone who can solve this issue?

    Comment

    • joedeene
      Contributor
      • Jul 2008
      • 579

      #3
      Are you just asking how to download and upload files on on https? Does this help: http://www.c-sharpcorner.com/UploadF...UsingHTTP.aspx.

      joedeene

      Comment

      • wolfenstein
        New Member
        • Mar 2008
        • 25

        #4
        Hi thanks for your reply as im really stuck here.
        Actually im trying to upload files on the client site HTTPS enabled. the client certificate is also available and imported in the browser.

        Now heres the code snippet that im using to achieve this functionality but its executes successfully and doesn't post any file.

        Code:
                StreamReader srDel = new StreamReader("C:\\test.txt");
                string sTestDelete = srDel.ReadToEnd();
                srDel.Close();
        
                string sDeleteURL = "https://sitename/folder";
        
                byte[] AuthBytes = Encoding.ASCII.GetBytes("uname:password");
                string sAuth = Convert.ToBase64String(AuthBytes);
                HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(sDeleteURL);
                HttpWebResponse oResponse = null;
                Request.Method = "POST";
        
                Request.Headers.Add("ContentType", "text/xml");
                Request.Headers.Add("Authorization", "Basic " + sAuth);
                Request.Headers.Add("dev-t", " OurDevToken ");
                Request.Headers.Add("UploadFor", "Marketplace");
        
                System.Security.Cryptography.X509Certificates.X509Certificate ClientCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate(@"C:\certificate.cer");
                Request.ClientCertificates.Add(ClientCertificate);
        
        byte[] SendByteArray = Encoding.GetEncoding(1252).GetBytes(sTestDelete);
        Request.ContentLength = SendByteArray.Length;
        
        Stream streamPostData = Request.GetRequestStream();
        streamPostData.Write(SendByteArray, 0, SendByteArray.Length);
        streamPostData.Close();
        
        oResponse = (HttpWebResponse)Request.GetResponse();
        StreamReader responseStream = new StreamReader(oResponse.GetResponseStream(), Encoding.ASCII);
        string sResponse = responseStream.ReadToEnd();
        
                Response.Write(sResponse);
        
                oResponse.Close();
                responseStream.Close();
        Can you please tell me where im going wrong as the code executes fine without any exception but no file is uploaded.
        Thanks!

        Comment

        • wolfenstein
          New Member
          • Mar 2008
          • 25

          #5
          Or is there any command line component is available for this purpose. Any work around to achieve this?

          Comment

          • wolfenstein
            New Member
            • Mar 2008
            • 25

            #6
            Still looking into this. Any suggestions or solution will highly be appreciated.
            Thanks!

            Comment

            • wolfenstein
              New Member
              • Mar 2008
              • 25

              #7
              Is there anyone on this forum who knows this issue and can provide some technical help?

              Comment

              • wolfenstein
                New Member
                • Mar 2008
                • 25

                #8
                Going Disappointing from here. No resolution yet :(

                Comment

                Working...