本文整理匯總了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;
}