123456789101112131415161718192021222324252627282930313233343536373839 |
- using Newtonsoft.Json;
- using Newtonsoft.Json.Converters;
- using System.Text;
- namespace AmrControl.Common.HttpClients
- {
- public class HttpPut : BaseHttpClient
- {
- /// <summary>
- /// 设置传输类型,请在请求时注意类型,
- /// </summary>
- 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>(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));
- }
- }
- }
- }
|