0

So I'm trying to pass a json string via the body of my clientFactory request. If I pass the json string via the URL, it works fine... my server side api is called and the json string is extracted from URL and request is processed and returns response correctly... However I'm wanting to do this the more common way and pass that json string request via the body. I imagine I need to pass it in a request header, but not quite sure... Would this work? (should json be escaped or not?)...


            var request = new HttpRequestMessage(HttpMethod.Post,
                "http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/);

            request.Headers.Add("Authorization", "Basic xxxxxxxxxxxxxxxxxxxxxxxx=");

            request.Headers.Add("text/plain", "{\"env\":\"xxx\",\"command\":\"getTrialKey\",\"payload\":{\"productCode\":\"MFT  102A08R EPCA 00007\"}}");

            var client = _clientFactory.CreateClient();
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

0 Answers0