예제 #1
0
            public void Write(EGTRequestStream requestStream, CyanRest restClient, string contentId)
            {
                byte[] contentBytes = null;
                if (entity != null)
                {
                    var content = entity.Serialize();
                    contentBytes = Encoding.UTF8.GetBytes(content.ToString());
                }

                var finalHeaders = new List<Tuple<string, string>>();
                finalHeaders.Add(Tuple.Create("Content-ID", contentId));
                if (contentBytes != null && contentBytes.Length > 0)
                {
                    finalHeaders.Add(Tuple.Create("Content-Type", "application/atom+xml;type=entry"));
                    finalHeaders.Add(Tuple.Create("Content-Length", contentBytes.Length.ToString()));
                }

                if (headers != null)
                    finalHeaders.AddRange(headers);

                // write status line
                requestStream.WriteLine("{0} {1} {2}", method, restClient.FormatUrl(resource), "HTTP/1.1");

                // write headers
                foreach (var header in finalHeaders)
                    requestStream.WriteHeader(header.Item1, header.Item2);
                requestStream.WriteLine();

                // write content
                if (contentBytes != null)
                {
                    requestStream.Write(contentBytes, 0, contentBytes.Length);
                    requestStream.WriteLine();
                }
            }