var request = new RestRequest(); Encoding.GetEncoding("ISO-8859-1"); code example

Example 1: var request = new RestRequest(); Encoding.GetEncoding("ISO-8859-1");

public Product GetProductDetails(string sku)
{
    var request = new RestRequest("api/v2/product/{sku}", Method.GET);
    request.AddParameter("sku", sku, ParameterType.UrlSegment);

    request.OnBeforeDeserialization = response =>
    {
        Encoding encoding = Encoding.GetEncoding("ISO-8859-1");
        response.Content = encoding.GetString(response.RawBytes);
    };

    try
    {
        return _baseClient.MakeRequest<Product>(request);
    }
    catch (Exception ex)
    {
        _logger.LogWarning(ex, "Failed to get product details");
        return new Product(sku);
    }
}

Example 2: var request = new RestRequest(); Encoding.GetEncoding("ISO-8859-1");

request.OnBeforeDeserialization = response =>
            {
                Encoding encoding = Encoding.GetEncoding("ISO-8859-1");
                response.Content = encoding.GetString(response.RawBytes);
            };

            try
            {
                var response = await client.ExecutePostTaskAsync<List<MyClaim>>(request).ConfigureAwait(false);

Example 3: var request = new RestRequest(); Encoding.GetEncoding("ISO-8859-1");

var request = new RestRequest(Method.GET);
var restResponse = client.Execute(request);

Encoding encoding = Encoding.GetEncoding("ISO-8859-1");
var result = encoding.GetString(response.RawBytes);
Console.WriteLine(result);

Tags:

Php Example