Showing results for 
Search instead for 
Did you mean: 
New Member

Sending PDF file converted to base64 to an Endpoint via HTTP POST request

Hi Guys.


I am using Xamarin Forms and I have a requirement which I must send a PDF file that is converted to base64 string to an API Endpoint.

I'm having trouble sending it. I always receive this error. 

"HTTP 406 Not Acceptable. There was an error with your request. Please check your payload and then try again."


This is the Endpoint and the details of the Json body.






x-axa-api-key: your-key

Content-Type: application/json


Request Body JSON


"file": {

"mime": "application/pdf",

"data": "base64-data="




Here is how I convert my PDF to base64


        private async Task ConvertPdf()
            const string pdfFileName = "MyPDF.pdf";

            using (var pdfStream = await FileSystem.OpenAppPackageFileAsync(pdfFileName))
                using (var pdfReader = new StreamReader(pdfStream))
                    var fileContents = await pdfReader.ReadToEndAsync();
                    pdfBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(fileContents));

        private async void Submit()
            var file = new MyFile();
            var pdf = new PdfFile();
            file.MimeType = "application/pdf";
            file.Base64Data = "base64-data=" + pdfBase64;
            pdf.myFile = file;
            await _iregister.Send(pdf.myFile);



This is my HTTP post request.

The myFile is my PDF that is already converted to base64 string.


            var apiKey = "######################";
            var jsonContent = JsonConvert.SerializeObject(myFile);
            string baseUrl = "";

            HttpClient httpClient = new HttpClient();
                .Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, baseUrl);
            requestMessage.Content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
            requestMessage.Headers.Add("x-axa-api-key", apiKey);

            HttpResponseMessage responseMessage = await httpClient.SendAsync(requestMessage);
            string responseAsString = await responseMessage.Content.ReadAsStringAsync();

            if (responseAsString != null)


Here is the format of the serialized JSON file. (I made it shorter just to show the format)




I am not sure if I am missing something in the Header or Body. Please help.

Super User
Super User

@stifler10 - Can you add accept header?


Accept: application/json

 Like and Mark this as answer if it resolves your issue.

Please Like and Mark this as Answer if it resolves your Issue.

Power Automate Community
New Member

Hi was this solve? Because I am also having thesame problem and error code.

Helpful resources

UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (2,659)