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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:19:46+00:00 2026-06-04T10:19:46+00:00

I have today a program that I can post through to my site, but

  • 0

I have today a program that I can post through to my site, but I need to add file upload support to my program (for jpg). I had such a problem just getting my program to post, and now after many hours I can’t get it to work with file upload.

Today my code is not very good but it works and I’m the only one using it.
Here is my code, abit stripped but I hope you get the idea what I need help with.
Thanks!

(“upfile” is the input field name for images)

public static string Post(string url, int id, string message)
{
    try
    {
        string param =
            string.Format(
                "MAX_FILE_SIZE=2097152&id={0}&com={1}&upfile", id, message);

        byte[] bytes = Encoding.ASCII.GetBytes(param);

        var post = (HttpWebRequest)WebRequest.Create(url);

        post.ProtocolVersion = HttpVersion.Version10;
        post.Method = "POST";
        post.AllowAutoRedirect = false;
        post.ContentType = "application/x-www-form-urlencoded";
        post.ContentLength = bytes.Length;

        post.UserAgent =
            "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.15) Gecko/2009101601 Firefox/3.0.15 (.NET CLR 3.5.30729)";
        post.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";

        Stream requestStream = post.GetRequestStream();
        requestStream.Write(bytes, 0, bytes.Length);
        requestStream.Close();

        var webResponse = (HttpWebResponse)post.GetResponse();
        var sr = new StreamReader(webResponse.GetResponseStream());
        return sr.ReadToEnd();
    }
    catch (Exception exception)
    {
        return null;
    }
}

Edit:
Sorry for my poor explanation here is what I need help with:
I use the method above today to post on my site, but I need add support to upload files in my method.
I can’t change how the webpage works in the close future so it have to be done by using a POST request.
I can’t get it to work then I try to do it myself, so I’m wondering if anybody could help me with what need to be added to read a image and post it with the request!

Thanks!

  • 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-04T10:19:48+00:00Added an answer on June 4, 2026 at 10:19 am

    You need to use the encoding of multipart/form-data instead of application/x-www-form-urlencoded, and then you need to encode the post data accordingly

    See Upload files with HTTPWebrequest (multipart/form-data)

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

Sidebar

Related Questions

Question: I have a dll that I can load in another program. Now the
Let's say I have a simple config file that my c program needs to
I have a program that gathers information from referring urls. Today i noticed that
I'm familiar with using NSLocalizedString() to localize strings, but the problem I have today
Today we have a windows application that, using an OCX, creates a web page
Today I have noticed that the order in which the $lt and $gt operators
Today I realized that I no longer have a Web Content Form option (where
I have a bunch of properties (configurations) that can change per environment. However these
I am building a website where I have a need that user should be
I have a VB6 program that someone recently helped me convert to VB.NET In

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.