Connecting Tech Pros Worldwide Forums | Help | Site Map

HTTP 405 Method Not allowed

Newbie
 
Join Date: Oct 2008
Location: Coimbatore
Posts: 29
#1: Dec 30 '08
we are trying to upload a file

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using System.Net;
  8.  
  9. namespace WindowsApplication3
  10. {
  11.     /// <summary>
  12.     /// Summary description for Form1.
  13.     /// </summary>
  14.     public class Form1 : System.Windows.Forms.Form
  15.     {
  16.         private System.Windows.Forms.Button button1;
  17.         /// <summary>
  18.         /// Required designer variable.
  19.         /// </summary>
  20.         private System.ComponentModel.Container components = null;
  21.  
  22.         public Form1()
  23.         {
  24.  
  25.             InitializeComponent();
  26.  
  27.  
  28.         }
  29.  
  30.         /// <summary>
  31.         /// Clean up any resources being used.
  32.         /// </summary>
  33.         protected override void Dispose( bool disposing )
  34.         {
  35.             if( disposing )
  36.             {
  37.                 if (components != null) 
  38.                 {
  39.                     components.Dispose();
  40.                 }
  41.             }
  42.             base.Dispose( disposing );
  43.         }
  44.  
  45.         #region Windows Form Designer generated code
  46.         /// <summary>
  47.         /// Required method for Designer support - do not modify
  48.         /// the contents of this method with the code editor.
  49.         /// </summary>
  50.         private void InitializeComponent()
  51.         {
  52.             this.button1 = new System.Windows.Forms.Button();
  53.             this.SuspendLayout();
  54.             // 
  55.             // button1
  56.             // 
  57.             this.button1.Location = new System.Drawing.Point(104, 96);
  58.             this.button1.Name = "button1";
  59.             this.button1.TabIndex = 0;
  60.             this.button1.Text = "button1";
  61.             this.button1.Click += new System.EventHandler(this.button1_Click);
  62.             // 
  63.             // Form1
  64.             // 
  65.             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  66.             this.ClientSize = new System.Drawing.Size(292, 273);
  67.             this.Controls.Add(this.button1);
  68.             this.Name = "Form1";
  69.             this.Text = "Form1";
  70.             this.ResumeLayout(false);
  71.  
  72.         }
  73.         #endregion
  74.  
  75.         /// <summary>
  76.         /// The main entry point for the application.
  77.         /// </summary>
  78.         [STAThread]
  79.         static void Main() 
  80.         {
  81.             Application.Run(new Form1());
  82.         }
  83.  
  84.         private void button1_Click(object sender, System.EventArgs e)
  85.         {
  86.             fnUpload();
  87.         }
  88.         public void fnUpload()
  89.         {
  90.             try
  91.             {
  92.                 WebClient  Client = new WebClient();
  93.                 //Client.UploadFile("http://www.csharpfriends.com/Members/index.aspx", "c:\wesiteFiles\newfile.aspx");
  94.                 Client.UploadFile("http://10.100.7.143/OETAdminWebService/123.zip", "C:\\123.zip");
  95.  
  96.  
  97.             }
  98.             catch(Exception ex)
  99.             {
  100.                 MessageBox.Show(ex.Message);
  101.             }
  102.         }
  103.     }
  104. }
while download its works

but upload is not working throwing an exception

HTTP 405 Method not allowed


we are change settings but its not working


thanks in advance

Happy New Year

With Regards,
Mani

kenobewan's Avatar
Moderator
 
Join Date: Dec 2006
Posts: 4,745
#2: Dec 31 '08

re: HTTP 405 Method Not allowed


Not sure why you posted to IIS forum? Looks like a coding problem, try debugging.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#3: Dec 31 '08

re: HTTP 405 Method Not allowed


A 405 error indicates:

The method specified in the Request-Line is not allowed for the resource identified by the Request-URI.

Check to make sure that you are allowed to access the resource:
"http://10.100.7.143/OETAdminWebService/123.zip"


Also, if the underlying request does not use HTTP or POST, the request for the resource is not understood by the server and a WebException is thrown with the Status property set to indicate the error.


So, make sure that the underlying request uses HTTP and POST.
For example:
Expand|Select|Wrap|Line Numbers
  1. String uriString = "http://10.100.7.143/OETAdminWebService/123.zip";
  2. String fileName = "C:\\123.zip";
  3. String method = "POST";
  4.  
  5. // Upload the file to the URL using the HTTP 1.0 POST.
  6. byte[] responseArray = Client.UploadFile(uriString, method, fileName);
  7.  
  8.  

-Frinny
Reply