public NoSuccessResponseWithJsonStringContent(string json, Conten_MediaType contentType, HttpStatusCode httpStatusCode, string reasonPhrase, string webServer, string date)
        {
            if (!(contentType == Conten_MediaType.ApplicationJson | contentType == Conten_MediaType.ApplicationProblemJson))
            {
                throw new InvalidOperationException($"The ContentType equal to \"{contentType.ToString()}\" cannot be assigned to this object");
            }

            this.Content        = json;
            this.ContentType    = contentType;
            this.HttpStatusCode = httpStatusCode;
            this.ReasonPhrase   = reasonPhrase;
            this.WebServer      = webServer;
            this.Date           = date;
        }
コード例 #2
0
        protected StringContent GetStringContentFromObject(object dto, Content_Encoding contentEncoding = Content_Encoding.UTF8, Conten_MediaType contentMediaType = Conten_MediaType.ApplicationJson)
        {
            Encoding encoding;

            switch (contentEncoding)
            {
            case Content_Encoding.UTF8:
                encoding = Encoding.UTF8;
                break;

            default:
                throw new NotImplementedException($"encoding: {contentEncoding} not implemented.");
            }

            string mediaType;

            switch (contentMediaType)
            {
            case Conten_MediaType.ApplicationJson:
                mediaType = MediaTypes.ApplicationJson;
                break;

            default:
                throw new NotImplementedException($"mediatype: {contentMediaType} not implemented.");
            }

            return(new StringContent(JsonSerializer.Serialize(dto, WebApiClientParameters.SerializerOptions), encoding, mediaType));
        }