我正在使用ObjectContent
这样构建 XML 请求:
private HttpRequestMessage CreateRequest<T>(T content, HttpMethod method) where T : class
{
// create http message request
var request = CreateRequest(method);
// set contents of the HTTP message
var xmlFormatter = new XmlMediaTypeFormatter
{
Indent = true,
UseXmlSerializer = true
};
var objectContent = new ObjectContent<T>(content, xmlFormatter);
request.Content = objectContent;
// return HttpRequestMessage
return request;
}
这很好用!但是,输出不包括 XML 序言,例如
<?xml version="1.0" encoding="UTF-8"?>
我怎样才能鼓励XmlSerializer
包括该行?