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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:17:25+00:00 2026-06-11T06:17:25+00:00

Can anybody help me resolve the problem for posting multipart/form-data using below code. I

  • 0

Can anybody help me resolve the problem for posting multipart/form-data using below code.

I have no idea about how to do it.

Please refer function PostTrivialData from post Question

  • 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-11T06:17:27+00:00Added an answer on June 11, 2026 at 6:17 am

    Here is the Code for Posting multipart data to URI:

    public string UploadChatFile(Stream fileStream, string uri, string postData, string fileName)
            {
                string boundary = "----------------------------" +
                DateTime.Now.Ticks.ToString("x");
    
                HttpWebRequest httpWebRequest2 = (HttpWebRequest)WebRequest.Create(uri);
                httpWebRequest2.ContentType = "multipart/form-data; boundary=" +
                boundary;
                httpWebRequest2.Method = "POST";
                httpWebRequest2.KeepAlive = true;
    
    
                Stream memStream = new System.IO.MemoryStream();
                byte[] boundarybytes = System.Text.Encoding.UTF8.GetBytes("\r\n--" + boundary + "\r\n");
    
                memStream.Write(boundarybytes, 0, boundarybytes.Length);
    
                string headerTemplate = string.Format("Content-Disposition: form-data; name=\"postdata\"\r\n{0}\r\n\r\n", postData);
    
                byte[] headerbytes = System.Text.Encoding.UTF8.GetBytes(headerTemplate);
    
                memStream.Write(headerbytes, 0, headerbytes.Length);
    
                memStream.Write(boundarybytes, 0, boundarybytes.Length);
    
                headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n Content-Type: application/octet-stream\r\n\r\n";
    
                //string header = string.Format(headerTemplate, "file" + i, files[i]);
                string header = string.Format(headerTemplate, "uplTheFile", fileName);
    
                headerbytes = System.Text.Encoding.UTF8.GetBytes(header);
    
                memStream.Write(headerbytes, 0, headerbytes.Length);
    
    
                //FileStream fileStream = new FileStream(file, FileMode.Open, FileAccess.Read);
                byte[] buffer = new byte[1024];
    
                int bytesRead = 0;
    
                while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
                {
                    memStream.Write(buffer, 0, bytesRead);
    
                }
                memStream.Write(boundarybytes, 0, boundarybytes.Length);
                fileStream.Close();
    
                httpWebRequest2.ContentLength = memStream.Length;
                Stream requestStream = httpWebRequest2.GetRequestStream();
                memStream.Position = 0;
                byte[] tempBuffer = new byte[memStream.Length];
                memStream.Read(tempBuffer, 0, tempBuffer.Length);
                memStream.Close();
                requestStream.Write(tempBuffer, 0, tempBuffer.Length);
                requestStream.Close();
    
                WebResponse webResponse2 = httpWebRequest2.GetResponse();
    
                Stream stream2 = webResponse2.GetResponseStream();
                StreamReader reader2 = new StreamReader(stream2);
    
                string responseString = reader2.ReadToEnd();
    
    
                return responseString;
            }
    

    This will post image and also you can include your data to postData parameter. You need to handle this PostData server carefully as it’s combined with multipart content data.

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

Sidebar

Related Questions

Can anybody help me with this? Here's the problem... When I have to code
Can anybody help me with this simple code?? #include <iostream> using namespace std; void
Can anybody help me with next: how can I use two different data contexts
Can anybody help(or point to some examples) about how to encrypt files with python?
I am facing SIGEV with this malloc wrapper code, can anybody please help me?
Can anybody help me to find out solution of following problem. In ASP.NET website:
I can't resolve this problem for 3 days. I have simple XML resource for
I have a problem that I cannot resolve, so if is anyone who can
Can anybody help, I`m starter in web? Here is code: <head> <meta http-equiv=Content-Type content=text/html;
Can anybody please help me to resolve this simple issue..How to clear the selection

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.