How do I post byte array picture using HttpWebRequest
?
img is a byte array.
Below is the code, when I use the parse function, I cannot convert byte[] img to string :
// Parse is the function to replace @xxx with a new string
string docString = Parse("action=@action&img=@img&signloclat=@lat&lng=@lng&id=@id",
"@action", "upload", "@img", img, "@lat", latitude, "@lng", longitude, "@id", id);
byte[] docByte = Encoding.ASCII.GetBytes(docString);
Uri wsHost = new Uri(EnpointAddress());
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(wsHost);
request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.ContentLength = docByte.Length;
Stream stream = request.GetRequestStream();
stream.Write(docByte, 0, docByte.Length);
stream.Close();
How can I post byte array with string using HttpWebRequest
?
Can I cast the byte array to string before sending?
Thank you.