src/EasyFrameWork/Net/WebApi/FormEncodedSerializer.cs

(完整代码) 1KB

/* http://www.zkea.net/ 
 * Copyright (c) ZKEASOFT. All rights reserved. 
 * http://www.zkea.net/licenses */

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;

namespace Easy.Net.WebApi
{
    public class FormEncodedSerializer : IRequestSerializer
    {
        public string GetContentTypeRegexPattern()
        {
            return MimeContentType.Form;
        }

        public object DeserializeResponse(HttpContent content, Type responseType)
        {
            throw new IOException($"Unable to deserialize Content-Type: {this.GetContentTypeRegexPattern()}.");
        }

        public HttpContent SerializeRequest(HttpRequest request)
        {
            if (!(request.Body is IEnumerable<KeyValuePair<string, string>>))
            {
                throw new IOException("Request requestBody must be IEnumerable<KeyValuePair<string, string>> when Content-Type is application/x-www-form-urlencoded");
            }

            return new FormUrlEncodedContent(request.Body as IEnumerable<KeyValuePair<string, string>>);
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。