asp.net web api - How to Post a file using Fiddler to WebAPI using C#? -


i new asp.net web api. have sample fileupload web api (from site) upload files server. but, don't know how test using fiddler.

http://localhost:54208/myapi/api/webapi/fileupload

on test.aspx page: following works fine. want know how use api using fiddler?

<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title> </head> <body>    <form enctype="multipart/form-data" method="post" action="http://localhost:54208/myapi/api/webapi/fileupload" id="ajaxuploadform" novalidate="novalidate">              <fieldset>                 <legend>upload form</legend>                 <ol>                     <li>                         <label>description </label>                         <input type="text" style="width:317px" name="description" id="description">                     </li>                     <li>                         <label>upload </label>                         <input type="file" id="fileinput" name="fileinput" multiple>                     </li>                     <li>                         <input type="submit" value="upload" id="ajaxuploadbutton" class="btn">                     </li>                 </ol>             </fieldset>         </form>  </body> </html>   public async task<httpresponsemessage> fileupload()        {            // check whether post operation multipart?            if (!request.content.ismimemultipartcontent())            {                throw new httpresponseexception(httpstatuscode.unsupportedmediatype);            }             // prepare custommultipartformdatastreamprovider in our multipart form            // data loaded.            //string filesavelocation = httpcontext.current.server.mappath("~/app_data");            string filesavelocation = httpcontext.current.server.mappath("~/uploadedfiles");            custommultipartformdatastreamprovider provider = new custommultipartformdatastreamprovider(filesavelocation);            list<string> files = new list<string>();             try            {                // read contents of multipart message custommultipartformdatastreamprovider.                await request.content.readasmultipartasync(provider);                 foreach (multipartfiledata file in provider.filedata)                {                    files.add(path.getfilename(file.localfilename));                }                 // send ok response along saved file names client.                return request.createresponse(httpstatuscode.ok, files);            }            catch (system.exception e)            {                return request.createerrorresponse(httpstatuscode.internalservererror, e);            }        }        // implement multipartformdatastreamprovider override filename of file        // stored on server, or else default name of format body-        // part_{guid}. in following implementation filename         // contentdisposition header of request body.        public class custommultipartformdatastreamprovider : multipartformdatastreamprovider        {            public custommultipartformdatastreamprovider(string path) : base(path) { }             public override string getlocalfilename(httpcontentheaders headers)            {                return headers.contentdisposition.filename.replace("\"", string.empty);            }        } 

help appreciated!


Comments