· Hi All,
I am trying to upload a file on HTTPS server.
File location : C:\data.text
Url: https://abc.com/Application/UploadLocation/
User ID: XXX
Password: XXX
I am using the below code:
Java
public void UploadY()
{
StreamReader srDel = new StreamReader("C:\\data.txt");
string sTestDelete = srDel.ReadToEnd();
srDel.Close();
string sDeleteURL = "https://abc.com/Application/UploadLocation/";
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", "application/xml");
Request.Headers.Add("ContentType", "text/xml");
Request.Headers.Add("Authorization", "Basic " + sAuth);
Request.Headers.Add("dev-t", " OurDevToken ");
Request.Headers.Add("UploadFor", "Marketplace");
string cerPath = @"C:\TestCert\cerNew.cer";
System.Security.Cryptography.X509Certificates.X509Certificate ClientCertificate = new
System.Security.Cryptography.X509Certificates.X509Certificate(cerPath);
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();
System.Web.HttpContext.Current.Response.Write(sResponse);
oResponse.Close();
responseStream.Close();
}Bui I am getting the below error:
{"The remote server returned an error: (405) Method Not Allowed."}
I tried to google it but could'nt find the solution.
If anyone could put some light on this problem.
Answers
Know the answer? Post it. Somebody with the same question will find it here.