title: Send ASCII string using HTTP Post
body: <p>I'm currently sending image data over as a byte array. However, I wish to send it over as ASCII string. How can I send an ASCII string from client to server using HTTP POST in c#? </p>
  
  <pre><code>    HttpWebRequest webRequest = null; 
      webRequest = (HttpWebRequest)HttpWebRequest.Create("http://192.168.1.2/"); 
      webRequest.ContentType = "application/x-www-form-urlencoded";                                            
      webRequest.Method = "POST";    
  
  //Assume here, I got the ascii string from image using ImageToBase64() function.
  
  byte[] buffer = encoding.GetBytes(myString)); //assume myString is an ASCII string
  
      // Set content length of our data 
      webRequest.ContentLength = buffer.Length; 
  
      webStream = webRequest.GetRequestStream(); 
      webStream.Write(buffer, 0, buffer.Length); //This is the only way I know how to send data -using byte array "buffer". But i wan to send data over as ASCII string "myString". How?
      webStream.Close(); 
  
      //I used this function to turn an image into ASCII string to be sent
      public string ImageToBase64(Image image, 
        System.Drawing.Imaging.ImageFormat format)
      {
        using (MemoryStream ms = new MemoryStream())
        {
          // Convert Image to byte[]
          image.Save(ms, format);
          byte[] imageBytes = ms.ToArray();
  
          // Convert byte[] to Base64 String
          string base64String = Convert.ToBase64String(imageBytes);
          return base64String;
        }
      }
  </code></pre>