Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7865947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:14:18+00:00 2026-06-03T00:14:18+00:00

I am trying to upload file on HTTP server using POST but when I

  • 0

I am trying to upload file on HTTP server using POST but when I call it gives error at
req.GetResponse(); in client code

The remote server returned an error: (405) Method Not Allowed.

client code

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string fileToUpload = Server.MapPath("~/Files/Ricky_Martin_Livin_la.mp3");
            string uploadUrl = "http://localhost/soundcheck/uploadfiles.aspx";
            //string uploadUrl = "http://10.0.2.2/musicapp/handle_upload.php";
            FileStream rdr = new FileStream(fileToUpload, FileMode.Open);
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uploadUrl);
            req.Method = "PUT"; // you might use "POST"
            req.ContentLength = rdr.Length;
            req.AllowWriteStreamBuffering = true;

            Stream reqStream = req.GetRequestStream();

            byte[] inData = new byte[rdr.Length];

            // Get data from upload file to inData 
            int bytesRead = rdr.Read(inData, 0, int.Parse(rdr.Length.ToString()));

            // put data into request stream
            reqStream.Write(inData, 0, int.Parse(rdr.Length.ToString()));

            rdr.Close();
            req.GetResponse();

            // after uploading close stream 
            reqStream.Close();
        }
    }

Server code

using System;
using System.Collections;
using System.IO;
using System.Data;
using System.Web;
using System.Text;
using System.Web.Security;

public partial class uploadfiles : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            LogInFile("First");
            HttpFileCollection uploadFile = Request.Files;
            LogInFile("Second");
            if (uploadFile.Count > 0)
            {
                HttpPostedFile postedFile = uploadFile[0];
                LogInFile("Thrid");
                System.IO.Stream inStream = postedFile.InputStream;
                LogInFile("Forth");
                byte[] fileData = new byte[postedFile.ContentLength];
                LogInFile("Fifth");
                inStream.Read(fileData, 0, postedFile.ContentLength);
                LogInFile("Sixth");
                postedFile.SaveAs(Server.MapPath("Data") + "\\" + postedFile.FileName);
            }        
        }
        catch (Exception ex)
        { 
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Message : " +ex.Message);
            sb.AppendLine("Source : " + ex.Source);
            sb.AppendLine("StackTrace : " + ex.StackTrace);
            sb.AppendLine("InnerException : " + ex.InnerException);
            sb.AppendLine("ToString : " + ex.ToString());

            LogInFile(sb.ToString());
        }
    }
    public void LogInFile(string str)
    {
        StringBuilder sb = new StringBuilder();
        using (StreamReader sr = new StreamReader(Server.MapPath("Data") + "\\expfile.txt"))
        {            
            sb.AppendLine("= = = = = =");
            sb.Append(sr.ReadToEnd());
            sb.AppendLine();
            sb.AppendLine();
        }
        sb.AppendLine(str);
        using (StreamWriter outfile = new StreamWriter(Server.MapPath("Data") + "\\expfile.txt"))
        {
            outfile.Write(sb.ToString());
        }
    }

}

In server code I write these Logs to track if there is any error or error at which line.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:14:20+00:00Added an answer on June 3, 2026 at 12:14 am
    req.Method = "PUT"; // you might use "POST"
    

    to

    req.Method = "POST"; 
    

    and try again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to upload a file to the server using a HTTP multipart form
friends, i am trying to upload file to php server using following tutorial http://getablogger.blogspot.com/2008/01/android-how-to-post-file-to-php-server.html
I am trying to upload file using dropbox api but following Code shows some
I was trying to upload file(s) using PrototypeJs request method but I failed. The
I'm trying to upload a file to a distant server, but looks like the
I am trying to upload an image to server using using XMLHttpRequest but fails.
im trying to upload a file using org.apache.commons.fileupload. but i dont no, what mistake
I'm trying to get the error handling to work for chunked file upload using
All, I'm trying to use the jQuery File Upload Demo: http://blueimp.github.com/jQuery-File-Upload/ My question is
Using the guide http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html i'm trying to customize error message, but i've a problem:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.