本文整理汇总了C#中System.Net.Http.HttpRequestMessage.SetODataContentId方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestMessage.SetODataContentId方法的具体用法?C# HttpRequestMessage.SetODataContentId怎么用?C# HttpRequestMessage.SetODataContentId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpRequestMessage
的用法示例。
在下文中一共展示了HttpRequestMessage.SetODataContentId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteMessageAsync_ResponseContainsContentId_IfHasContentIdInRequestChangeSet
public void WriteMessageAsync_ResponseContainsContentId_IfHasContentIdInRequestChangeSet()
{
MemoryStream ms = new MemoryStream();
HttpContent content = new StringContent(String.Empty, Encoding.UTF8, "multipart/mixed");
content.Headers.ContentType.Parameters.Add(new NameValueHeaderValue("boundary", Guid.NewGuid().ToString()));
IODataResponseMessage odataResponse = new ODataMessageWrapper(ms, content.Headers);
var batchWriter = new ODataMessageWriter(odataResponse).CreateODataBatchWriter();
HttpResponseMessage response = new HttpResponseMessage
{
Content = new StringContent("any", Encoding.UTF8, "text/example")
};
var request = new HttpRequestMessage();
var contentId = Guid.NewGuid().ToString();
request.SetODataContentId(contentId);
response.RequestMessage = request;
batchWriter.WriteStartBatch();
batchWriter.WriteStartChangeset();
ODataBatchResponseItem.WriteMessageAsync(batchWriter, response, CancellationToken.None).Wait();
batchWriter.WriteEndChangeset();
batchWriter.WriteEndBatch();
ms.Position = 0;
string result = new StreamReader(ms).ReadToEnd();
Assert.Contains("any", result);
Assert.Contains("text/example", result);
Assert.Contains("Content-ID", result);
Assert.Contains(contentId, result);
}
示例2: SetODataContentId_SetsTheContentIdOnTheRequest
public void SetODataContentId_SetsTheContentIdOnTheRequest()
{
HttpRequestMessage request = new HttpRequestMessage();
var id = Guid.NewGuid().ToString();
request.SetODataContentId(id);
Assert.Equal(id, request.GetODataContentId());
}
示例3: ReadOperationInternalAsync
private static async Task<HttpRequestMessage> ReadOperationInternalAsync(
ODataBatchReader reader, Guid batchId, Guid? changeSetId, CancellationToken cancellationToken, bool bufferContentStream = true)
{
ODataBatchOperationRequestMessage batchRequest = reader.CreateOperationRequestMessage();
HttpRequestMessage request = new HttpRequestMessage();
request.Method = new HttpMethod(batchRequest.Method);
request.RequestUri = batchRequest.Url;
if (bufferContentStream)
{
using (Stream stream = batchRequest.GetStream())
{
MemoryStream bufferedStream = new MemoryStream();
// Passing in the default buffer size of 81920 so that we can also pass in a cancellation token
await stream.CopyToAsync(bufferedStream, bufferSize: 81920, cancellationToken: cancellationToken);
bufferedStream.Position = 0;
request.Content = new StreamContent(bufferedStream);
}
}
else
{
request.Content = new LazyStreamContent(() => batchRequest.GetStream());
}
foreach (var header in batchRequest.Headers)
{
string headerName = header.Key;
string headerValue = header.Value;
if (!request.Headers.TryAddWithoutValidation(headerName, headerValue))
{
request.Content.Headers.TryAddWithoutValidation(headerName, headerValue);
}
}
request.SetODataBatchId(batchId);
request.SetODataContentId(batchRequest.ContentId);
if (changeSetId != null && changeSetId.HasValue)
{
request.SetODataChangeSetId(changeSetId.Value);
}
return request;
}