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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:57:17+00:00 2026-06-01T07:57:17+00:00

i convert an image to base64 string to upload through HttpWebRequest in c#.on server

  • 0

i convert an image to base64 string to upload through HttpWebRequest in c#.on server side when i receive base64 string the “+” signs have been converted to white spaces” “. it give me error to convert this base64 string to byte array.i do not want to make any change on server side(in web services). i want to resolve this issues on client side.my client side code is as follow.

//////////////////

WSManagerResult wsResult = new WSManagerResult();

        try
        {
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(serviceURL);
            req.Method = "POST";
            req.ProtocolVersion = HttpVersion.Version11;
            req.ContentType = "application/x-www-form-urlencoded";
            //  req.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
            // req.CookieContainer = new CookieContainer();


            string content = string.Empty;
            foreach (KeyValuePair<string, string> entry in paramDic)
            {

// entry.Value is a base 64 string gene rated from image

             content = content + entry.Key + "=" + entry.Value + "&&";
            }
            content = content.TrimEnd('&'); // input parameter if u have more that one //a=b&dd=aa               
            req.ContentLength = content.Length;
            // req = URLEncode(content);
            Stream wri = req.GetRequestStream();


            byte[] array = Encoding.ASCII.GetBytes(content);
            if (array.Length > 0)
                wri.Write(array, 0, array.Length);
            wri.Flush();
            wri.Close();
            WebResponse rsp = (HttpWebResponse)req.GetResponse();


            byte[] b = null;
            using (Stream stream = rsp.GetResponseStream())
            using (MemoryStream ms = new MemoryStream())
            {
                int count = 0;
                do
                {
                    byte[] buf = new byte[1024];
                    count = stream.Read(buf, 0, 1024);
                    ms.Write(buf, 0, count);
                } while (stream.CanRead && count > 0);
                b = ms.ToArray();
            }
            wsResult.result = Encoding.ASCII.GetString(b);
        }
        catch (Exception e)
        {
            clsException.ExceptionInstance.HandleException(e);
            wsResult.error = e.Message;
        }


        return wsResult;

All the “+” signs in above base64 string are converted in to ” ” white spaces.which causes the issue as describe above.

Please help me to resolve this issue.

Regards

shah Khalid

  • 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-01T07:57:19+00:00Added an answer on June 1, 2026 at 7:57 am

    There exists an encoding called Base64Url encode that’s designed for just that. However you may have to do the encoding / decoding on their respective ends.

    In Base64 Url, it converts + to - and / to _ so that it can be safely passed over the wire without the standard URL encoders adding weirdness like spaces, or percent-hex

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

Sidebar

Related Questions

public Image Base64ToImage(string base64String) { // Convert Base64 String to byte[] byte[] imageBytes =
I am trying to convert a base64 encoded string to an image object using
I use the following method to convert an image to a base64 string: FileStream
I have a base64 encoded string that I would like to convert into an
is there some way to convert a base64 string into an image; in Visual
I have a PNG image and got its Base64 PNG string representation. It's still
I have searched on the web for software that batch convert image at different
I have an application, currently written in C#, which can take a Base64-encoded string
I am trying to convert bitmap images into a base64 string before inserting it
Hi stackoverflow team i have a problem in converting base64 string to bitmap 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.