Skip to main content
Download images with RestSharp
  1. Posts/

Download images with RestSharp

·143 words·1 min
Christoph Petersen
Author
Christoph Petersen

We are using RestSharp for functional testing of our backend services. As part of this process we need to upload images and compare the uploaded bytes against the expected result.

RestSharp comes with a default parameter which sets the Accept header. The default is set to something like this:

DefaultParameter set by RestSharp

Whenever you try to request data that sports a different content-type you’ll receive a 406 return code from the server but not the actual response you’re looking for.

For our example we need to download image data (in most cases either JPEG or PNG). It is pretty simple to change the default parameter and add additional content types that you need:

var client = new RestClient();
client.DefaultParameters.Single(p => p.Name == "Accept").Value += ", image/*";

In this example I’m adding image/* as acceptable content type and downloading images from the server works like a charm.

Related

Use Azure Artifacts outside of Visual Studio

·438 words·3 mins
One of the major tasks since starting at HorseAnalytics has been to streamline our development efforts. Centralize the codebase on Azure Repos, refactor the code so that it can not only be built on Windows but also on other platforms like Mac OS.

Fetching all branches and tags from a remote Git repository

·164 words·1 min
In my first days at HorseAnalytics, one of the first tasks was to review the codebase and streamline the build and release process. That meant to move all repositories over to Azure DevOps so that we can use the pipelines to build and release new versions of our products.

Remove data from BACPAC file

·158 words·1 min
Today I needed to create a test database for one of the products I’m working on. In the backend it uses LINQ to SQL against a SQL Azure Database. Exporting the production database and cleaning it up with millions of records in it turned out to be not the most efficient way of creating an empty test database.