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 8339795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:58:51+00:00 2026-06-09T04:58:51+00:00

The problem with this code is that the file, once it is uploaded, is

  • 0

The problem with this code is that the file, once it is uploaded, is not the correct format. I’m trying to upload a .zip file.

public string HttpPost(string uri, string parameter)
{
WebRequest webRequest = WebRequest.Create(uri);

        NetworkCredential credentials = new NetworkCredential("username", "password");
        webRequest.Credentials = credentials;

        webRequest.ContentType = "application/x-www-form-urlencoded";
        webRequest.Method = "POST";

        byte[] bytes = Encoding.ASCII.GetBytes(parameter);
        Stream os = null;
        try
        { // send the Post
            webRequest.ContentLength = bytes.Length;   //Count bytes to send
            os = webRequest.GetRequestStream();
            os.Write(bytes, 0, bytes.Length);         //Send it
        }
        catch (WebException ex)
        {
            MessageBox.Show(ex.Message, "HttpPost: Request error",
               MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        finally
        {
            if (os != null)
            {
                os.Close();
            }
        }

        try
        { // get the response
            WebResponse webResponse = webRequest.GetResponse();
            if (webResponse == null)
            { return null; }
            StreamReader sr = new StreamReader(webResponse.GetResponseStream());
            return sr.ReadToEnd().Trim();
        }
        catch (WebException ex)
        {
            MessageBox.Show(ex.Message, "HttpPost: Response error",
               MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        return null;
    } 
  • 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-09T04:58:53+00:00Added an answer on June 9, 2026 at 4:58 am

    This example how to upload file in MyBucket

        private const string KeyId = "Your KeyId";
        private const string AccessKey = "Your AccessKey";
        private const string S3Url = "https://s3.amazonaws.com/";
    
                private static void UploadFile()
        {
            var fileData = File.ReadAllBytes(@"C:\123.zip");
    
            string timeStamp = string.Format("{0:r}", DateTime.UtcNow);
            string stringToConvert = "PUT\n" +                               //Http verb
                "\n" +                                                       //content-md5
                "application/octet-stream\n" +                               //content-type
                "\n" +                                                       //date
                "x-amz-acl:public-read"+"\n" +                               //date
                "x-amz-date:" + timeStamp + "\n" +                           //optionall
                "/MyBucket/123.zip";                                         //resource
            var ae = new UTF8Encoding();
            var signature = new HMACSHA1 {Key = ae.GetBytes(AccessKey)};
            var bytes = ae.GetBytes(stringToConvert);
            var moreBytes = signature.ComputeHash(bytes);
            var encodedCanonical = Convert.ToBase64String(moreBytes);
    
            var url = "https://MyBucket.s3.amazonaws.com/123.zip";
    
            var request = WebRequest.Create(url) as HttpWebRequest;
            request.Method = "PUT";
            request.Headers["x-amz-date"] = timeStamp;
            request.Headers["x-amz-acl"] = "public-read";
            request.ContentType = "application/octet-stream";
            request.ContentLength = fileData.Length;
            request.Headers["Authorization"] = "AWS " + KeyId + ":" + encodedCanonical;
    
            var requestStream = request.GetRequestStream();
            requestStream.Write(fileData, 0, fileData.Length);
            requestStream.Close();
    
            using (var response = request.GetResponse() as HttpWebResponse)
            {
                var reader = new StreamReader(response.GetResponseStream());
                var data = reader.ReadToEnd();
            }
        }
    

    Take a look on Amazon S3 REST API

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

Sidebar

Related Questions

I am trying to solve this exponentiation problem . Here is the code that
I'm running the following code on a file that has been uploaded to this
I got this code today that works for jQuery v7. The problem is that
hi i'm having a problem with this code. my problem is that the first
The Problem I'm receiving crash reports from users that look like this: Code Type:
Here is a JSFiddle that demonstrates the problem... http://jsfiddle.net/L2NBP/5/ For obvious reasons this code
So my next problem with this code. It seemse to not be finding a
I have a problem in this code when I enter a string, instead of
I have a problem with this code: (The error is below the code) public
I'm trying to write some code that deletes an image off the hard-disk once

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.