469,356 Members | 1,947 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

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!
Nov 21 '08 #1
7 10993
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?
Nov 21 '08 #2
joedeene
583 512MB
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
Nov 21 '08 #3
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.

Expand|Select|Wrap|Line Numbers
  1.         StreamReader srDel = new StreamReader("C:\\test.txt");
  2.         string sTestDelete = srDel.ReadToEnd();
  3.         srDel.Close();
  4.  
  5.         string sDeleteURL = "https://sitename/folder";
  6.  
  7.         byte[] AuthBytes = Encoding.ASCII.GetBytes("uname:password");
  8.         string sAuth = Convert.ToBase64String(AuthBytes);
  9.         HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(sDeleteURL);
  10.         HttpWebResponse oResponse = null;
  11.         Request.Method = "POST";
  12.  
  13.         Request.Headers.Add("ContentType", "text/xml");
  14.         Request.Headers.Add("Authorization", "Basic " + sAuth);
  15.         Request.Headers.Add("dev-t", " OurDevToken ");
  16.         Request.Headers.Add("UploadFor", "Marketplace");
  17.  
  18.         System.Security.Cryptography.X509Certificates.X509Certificate ClientCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate(@"C:\certificate.cer");
  19.         Request.ClientCertificates.Add(ClientCertificate);
  20.  
  21. byte[] SendByteArray = Encoding.GetEncoding(1252).GetBytes(sTestDelete);
  22. Request.ContentLength = SendByteArray.Length;
  23.  
  24. Stream streamPostData = Request.GetRequestStream();
  25. streamPostData.Write(SendByteArray, 0, SendByteArray.Length);
  26. streamPostData.Close();
  27.  
  28. oResponse = (HttpWebResponse)Request.GetResponse();
  29. StreamReader responseStream = new StreamReader(oResponse.GetResponseStream(), Encoding.ASCII);
  30. string sResponse = responseStream.ReadToEnd();
  31.  
  32.         Response.Write(sResponse);
  33.  
  34.         oResponse.Close();
  35.         responseStream.Close();
  36.  
Can you please tell me where im going wrong as the code executes fine without any exception but no file is uploaded.
Thanks!
Nov 21 '08 #4
Or is there any command line component is available for this purpose. Any work around to achieve this?
Nov 22 '08 #5
Still looking into this. Any suggestions or solution will highly be appreciated.
Thanks!
Nov 23 '08 #6
Is there anyone on this forum who knows this issue and can provide some technical help?
Nov 25 '08 #7
Going Disappointing from here. No resolution yet :(
Nov 27 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Jonathan Wax | last post: by
2 posts views Thread by Jonathan Wax | last post: by
1 post views Thread by theburnetts | last post: by
reply views Thread by Buddy Home | last post: by
2 posts views Thread by =?Utf-8?B?SHVzYW0=?= | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.