Explicitly encoding your content

You can also choose to explicitly encode your content. The image encoder, for instance, encodes images to PNG files. If you want to encode the image to another file format, you can explicitly do so, as follows:

private void ReturnMomentaryAsJpg(HttpRequest Request, 
   HttpResponse Response) 
{ 
   SKImage Gauge = this.GenerateGauge(Request.Header); 
   SKData Data = Gauge.Encode(SKEncodedImageFormat.Jpeg, 90); 
   byte[] Binary = Data.ToArray(); 
 
   Response.ContentType = "image/jpeg"; 
   Response.Write(Binary); 
} 

Here you must explicitly set the content type of the response and then write the binary encoded data to the response stream.

You can now run the application and test it by typing in the URL of your new resource.

To test different representations of the same resource, you can download plugins to several of the web browsers available that allow you to customize HTTP headers in requests. This allows you to modify the Accept header and see how you get different responses depending on the values you provide.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset