Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to do httpPost to a webservice which accepts a byte array of a file using c#
    primarykey
    data
    text
    <p>I am working on an API kind of project,</p> <p>I have wrote a WebMethod <em>(not exactly. I am using MVC to create REST like API)</em></p> <pre><code>public UploadFileImage(string employeeId, byte[] imageBytes, string imageName) { // saves the imagebyte as an image to a folder } </code></pre> <p>the web service would be consumed by a web app, or windows or even iphone or such portable stuffs. I am testing my web service using a web app, by simple httpPost.</p> <pre><code>string Post(Uri RequestUri, string Data) { try { HttpWebRequest request = HttpWebRequest.Create(RequestUri) as HttpWebRequest; request.Method = "POST"; request.ContentType = IsXml.Checked ? "text/xml" : "application/x-www-form-urlencoded"; byte[] bytes = Encoding.ASCII.GetBytes(Data); Stream os = null; // send the Post request.ContentLength = bytes.Length; //Count bytes to send os = request.GetRequestStream(); os.Write(bytes, 0, bytes.Length); HttpWebResponse httpWebResponse = (HttpWebResponse)request.GetResponse(); StreamReader streamReader = new StreamReader(request.GetResponse().GetResponseStream()); return streamReader.ReadToEnd(); } catch (Exception ex) { return ex.Message; } } </code></pre> <p>This code works fine for evey method like, AddEmployee, DeleteEmployee etc. THe parameter Data is of form "Id=123&amp;name=abcdefgh&amp;desig=Developer",</p> <p>How I call any other function is Post(new Uri("http://localhost/addemployee"),"name=abcd&amp;password=efgh")<br> where post is the function i wrote. </p> <p>All good for all functions. Except that I dont know how to consume the above mentioned function UploadFileImage to upload an image?</p> <p>Thanks </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload