dimanche 26 mai 2019

HTTPClient Post Request with Headers and Body

I want to set the Content-Type and Authorization Headers using HttpClient and want to load the xml file for the body(request) and send Post request.

I have searched for combining both headers and body for Post request.

Setting up the Headers using HttpRequestMessage.

   HttpClient clientTest = new HttpClient();

   HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Post,url);


   httpRequest.Content = new StringContent(string.Empty, Encoding.UTF8, "application/vnd.citrix.sessionparams+xml");
   httpRequest.Headers.Authorization = new AuthenticationHeaderValue("CitrixAuth", "H4sIAAAAAAAEAK1X2Y6jyBL9lZLnEbnZt1J");

Setting the xml body -

XDocument xml = XDocument.Load("RequestSession.xml");

Converting to Document.ToString()

var httpContent = new StringContent(xml.Document.ToString(), Encoding.UTF8, "application/vnd.citrix.sessionstate+xml");

Please help me with combining both headers and body for Post Request using HttpClient.




Aucun commentaire:

Enregistrer un commentaire