Vinh Nguyen

406 Error When Retrieving Attachment

0 votes


I have a method to Retrieve the attachment:

public async Task<byte[]> GetAttachmentContentAsync(string packageId, string attachmentId)


   // Validate the request parameter against a known fixed string or valid source of IP address
   if (!Uri.TryCreate($"packages/{packageId}/attachment/{attachmentId}", UriKind.Relative, out Uri uri))
       throw new ArgumentException("Invalid URI");

   var response = await _httpClient.GetAsync(uri);


   if (!response.IsSuccessStatusCode)
       throw new CriticalException($"Remote service returned error code {response.StatusCode}" +
                                   $" with content {await response.Content.ReadAsStringAsync()}", response);

   return await response.Content.ReadAsByteArrayAsync();

When making calls to: 


I got 604 Not Acceptable.


However, getting other docs works just find (the code is remarkably similar as above)




Approved Answer

Reply to: 406 Error When Retrieving Attachment

0 votes

Hi Vinh Nguyen,


Thanks for your post! In short, can you try to use either "*/*" or "application/octet-stream" as accept header? Below is a quick example that works for me:


           string url = $"{API_URL}/packages/8L5qG0I5PU0pKct5s6zX8IEv-uY=/attachment/jaIW5qJGrfQT";

           HttpClient myClient = new HttpClient();
           myClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", API_KEY);
           myClient.DefaultRequestHeaders.Add("Accept", "*/*");

           var attResponse = myClient.GetAsync(new Uri(url)).Result;
           ByteArrayContent content = new ByteArrayContent(attResponse.Content.ReadAsByteArrayAsync().Result);
           File.WriteAllBytes("..\\driver license.png", content.ReadAsByteArrayAsync().Result);
           Debug.WriteLine("Attachment Downloaded");




Duo Liang OneSpan Evangelism and Partner Integrations Developer

Reply to: 406 Error When Retrieving Attachment

0 votes

It works, thanks alot.

Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off