I need to send XML request to REST API , it is Get Request (i cannot use Post). This code is working from Postman but in C# .Net 4.8.1 framework this code is not working , i am getting error 'Cannot send a content-body with this verb-type.'
I google a lot but getting answer , lot of people have same issue.
What wrong am I doing ? Thanks. Here is Code.
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "http://XXXX/get/getFees");
request.Headers.Add("Authorization", "Basic XXXX);
request.Headers.Add("Cookie", "JSESSIONID=XXXX");
var content = new StringContent("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n <soap:Body>\r\n\r\n </soap:Body>\r\n</soap:Envelope>", null, "text/plain");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());