I am a newbie in using Refit. I am using Refit now to call a REST Api that expects xml as input. This works but it seems that Refit automatically adds the well known xml preamble to describe encoding.
I want to send the xml element without preamble (as required by the target system). How do I do this? Here is my code in the startup class:
var settings = new RefitSettings
{
ContentSerializer = new XmlContentSerializer()
};
services.AddRefitClient<IItemApi>(settings)
.ConfigureHttpClient(c => c.BaseAddress = new Uri("http://127.0.0.1:5000"));
Here is my data class and just used interface
public class PayLoad
{
public string A { get; set; }
public string B { get; set; }
}
public interface IItemApi
{
[Post("/target/{id}")]
Task<ApiResponse<string>> PostItemAsync(string id, [Body] PayLoad item,
CancellationToken cancellationToken = default);
}
Here is an example of a post call:
var result = itemApi.PostItemAsync("X",new PayLoad
{
A = "A",
B = "B"
});
This is the raw request:
POST http://127.0.0.1:5000/target/X HTTP/1.1
Content-Type: application/xml; charset=utf-8
Content-Length: 76
Host: 127.0.0.1:5000
<?xml version="1.0" encoding="utf-8"?><PayLoad><A>A</A><B>B</B></PayLoad>
How can I change my code in such a way this part
<?xml version="1.0" encoding="utf-8"?>
is not in the request anymore?