web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Error while calling a web services using parameters

(0) ShareShare
ReportReport
Posted on by 170

Hi,

I'm getting the errors below when I try to call a web service. Calling GET works fine, it just return the structure of webservice but when I try to call POST, I get always errors. What might be wrong with my code? It's C#.

        public static async Task GetResponse(string token)
        {
            string body;

            var client = new HttpClient();
            client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
            var request = new HttpRequestMessage
            {

                Method = HttpMethod.Post,
                RequestUri = new Uri("https://example/namespaces/AXSF/api/services/ProjectServices/ProjectWbsService/getProjectInfo"),
                Content = new FormUrlEncodedContent(new Dictionary
                {
                    { "company", "" },
                    { "recordId", "" },
                }),
            };
            using (var response = await client.SendAsync(request))
            {
                response.EnsureSuccessStatusCode();
                body = await response.Content.ReadAsStringAsync();
                Console.WriteLine(body);
            }

            return body;
        }

An exception occured when deserializing the request - Exception occured when parsing the request content - Unexpected character encountered while parsing value: c. Path '', line 0, position 0.".

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    236,477 Most Valuable Professional on at
    RE: Error while calling a web services using parameters

    What you should pass to the service operation is a JSON object. For example:

    var contract = new { company = "", recordId = 0 };
    string json = JsonConvert.SerializeObject(contract);

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,964

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 823 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 564 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans