using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Text;
namespace AmrControl.Common.HttpClients
{
public class HttpPut : BaseHttpClient
{
///
/// 设置传输类型,请在请求时注意类型,
///
private MediaType mediaType = MediaType.APPLICATION_JSON_VALUE;
public HttpPut(HttpClient httpClient, string baseUri) : base(httpClient, baseUri)
{
}
public void setMediaType(MediaType type)
{
this.mediaType = type;
}
protected override HttpMethod getMethod()
{
return HttpMethod.Put;
}
protected override HttpContent? handleData(T data)
{
if (mediaType == MediaType.APPLICATION_JSON_VALUE)
{
//请求内容在请求体中时使用
return new StringContent(JsonConvert.SerializeObject(data, new IsoDateTimeConverter() { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" }), Encoding.UTF8, "application/json");
}
else
{
return new FormUrlEncodedContent(convertObj2Dict(data));
}
}
}
}