繁体   English   中英

ASP.NET Core 5 httpclient 使用 xml

[英]ASP.NET Core 5 httpclient using xml

httpClient与 XML 一起使用来发帖和接听电话的首选方式是什么?

public class ShippingService : IShippingService
{
    private readonly HttpClient _httpClient;
    private readonly string _remoteServiceBaseUrl;

    public CatalogService(HttpClient httpClient)
    {
        _httpClient = httpClient;
    }

    public async Task<List<ShippingPrice>> GetShippingPrices()
    {
         // httpClient post using xml format
    }
}

核实:

   HttpClient _httpClient = new HttpClient();
   string xml = ""; //serialize your object
   var content = new StringContent(xml, Encoding.UTF8, "application/xml");
   await _httpClient.PostAsync("http://example.com/api",content);

要将 object 序列化为 xml,请参见: XML Serialize generic list of serializable objects

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM