Search This Blog

Showing posts with label Advanced REST Client. Show all posts
Showing posts with label Advanced REST Client. Show all posts

Sunday, July 15, 2018

Getting OperationCancelledException in your c# WebApi tests, using Advanced Rest Client as the http client tool ?

Make sure the Request Behavior -> Request Timeout setting suits your needs.
I was making a request that takes around a minute to return from the database, but Advanced Rest Client was quitting it before my Web Api project could return the data, because its Request Timeout setting was too small.

Tuesday, May 12, 2015

Http Request To Upload File(s) To The Server In ASP.NET Web Api

Instructions: if you need to attach files to a http request to upload them to a server, here's basically what you need to do:

  1. In your api post method, you need to verify that the request contains files, via Request.Content.IsMimeMultipartContent
  2. Go through the files attached to the request, using HttpContext.Request.Files, casting them to HttpPostedFileBase.
  3. Now you do what you want with the files.
To test this using a http client like google's Advanced REST Client, simply mark the request as a post method, and you will be able to click a "Files" option, like the in the image below:


Usage:
            try
            {
                if (Request.Content.IsMimeMultipartContent())
                {
                    HttpFileCollectionBase files = this.UmbracoContext.HttpContext.Request.Files;
                    foreach (String uploadedFileName in files)
                    {
                        HttpPostedFileBase httpPostedFileBase = files[uploadedFileName] as HttpPostedFileBase;

                        /* do what you want with the file, here */
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }