コード例 #1
0
        public string SerializeSubRequest(SubRequest request)
        {
            string requestBody = serializer.SerializeObject(request.Body);

            StringBuilder messagePayload = new StringBuilder()
                                           .Append($"POST {request.Url} HTTP/1.1\r\n")
                                           .Append($"Content-Length: {requestBody.Length}\r\n")
                                           .Append("Content-Type: application/json; charset=UTF-8\r\n");

            if (request.Headers != null)
            {
                foreach (var header in request.Headers)
                {
                    messagePayload.Append($"{header.Key}: {header.Value}\r\n");
                }
            }
            messagePayload.Append("\r\n");
            messagePayload.Append(requestBody);

            return(messagePayload.ToString());
        }